wscompile JAX-RPC generates Calendar object instead of Date

1.4k views Asked by At

I have a problem when generating java classes from WSDL using JAX-RPC wscompile ANT task.

My ant script:

<taskdef name="wscompile" classname="com.sun.xml.rpc.tools.ant.Wscompile" classpathref="jaxrpc.classpath"/>
<taskdef name="wsdeploy" classname="com.sun.xml.rpc.tools.ant.Wsdeploy" classpathref="jaxrpc.classpath"/>
<wscompile
        fork="true"
        base="${target.jaxrpc.dir}"
        server="true"
        client="false"
        features="documentliteral"
        model="${target.jaxrpc.dir}/model.xml.gz"
        debug="true"
        keep="true"
        verbose="true"
        config="${src.main.config.dir}/jaxrpc-service-config.xml">
    <classpath refid="jaxrpc.classpath"/>
</wscompile>

In my wsdl there is Date type objects, the problem is that JAX-RPC generates Calendar objects. Is there a way to set some flag or somehow to force JAX-RPC to generate Date objects?

1

There are 1 answers

2
Rupeshit On BEST ANSWER

This is because the Enterprise Web Services 1.1 specification defines the default mapping between Java classes and XML types.However you can change the default mapping for your application.You can change the mapping by editing the contents of the element JAX-RPC mapping file. In your case you have to do following changes:

    <java-wsdl-mapping>
      ...
       <java-xml-type-mapping>
       <java-type>java.util.Date</java-type>
      <root-type-qname xmlns:qn="http://www.w3c.org/2001/XMLSchema">qn:dateTime</root-type-qname>
     </java-xml-type-mapping>
      ...
    <java-wsdl-mapping>