Search code examples
javaxmlweb-servicesjaxbjax-ws

Generate xs:date instead of xs:dateTime for WebParam


I have a jax-ws web-service with web-method:

@WebMethod
void SetCurrentDate(Date date)

In generated wsdl parameter date has type xs:dateTime, but i need xs:date. I tried XmlGregorianCalendar, but it maps to xs:anySimpleType, also i tried @XmlSchemaType, but it's not allowed for parameters. How can I generate wsdl with xsd:date instead of xsd:dateTime?


Solution

  • Looks like only way to do it is by using annotation @RequestWrapper (for jax-ws-impl and apache cxf):

    @WebMethod
    @RequestWrapper(className = "....SetCurrentDateRequest")
    void SetCurrentDate(Date date)
    

    And request wrapper:

    @XmlAccessorType(XmlAccessType.FIELD)
    @XmlType(name = "setCurrentDateRequest", propOrder = {
        "date"
    })
    public class SetCurrentDateRequest {
    
        @XmlSchemaType(name="date")
        protected Date date;
    
        public Date getDate() {
            return date;
        }
    
        public void setDate(Date date) {
            this.date = date;
        }
    }
    

    CXF/JAXB Code-first service: modify XMLSchemaType of inputs