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?

Upvotes: 1

Views: 2942

Answers (2)

Amir
Amir

Reputation: 26

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

Upvotes: 1

Ilya
Ilya

Reputation: 29711

@XmlSchemaType is enough to do it.
Both

@XmlSchemaType(name = "date")
protected Date publishDate;  

and

@XmlSchemaType(name = "date")
protected XMLGregorianCalendar publishDate;  

are generated to type="xs:date" (with schemagen tool)

See examples here

Example 1: Customize mapping of XMLGregorianCalendar on the field.

 //Example: Code fragment
 public class USPrice {
     @XmlElement
     @XmlSchemaType(name="date")
     public XMLGregorianCalendar date;
 }

 <!-- Example: Local XML Schema element -->
 <xs:complexType name="USPrice"/>
   <xs:sequence>
     <xs:element name="date" type="xs:date"/>
   </sequence>
 </xs:complexType>

Example 2: Customize mapping of XMLGregorianCalendar at package level

 package foo;
 @javax.xml.bind.annotation.XmlSchemaType(
      name="date", type=javax.xml.datatype.XMLGregorianCalendar.class)
 }

Upvotes: 0

Related Questions