<?xml version="1.0" encoding="utf-8"?>
<rss xmlns:atom="http://www.w3.org/2005/Atom" version="2.0"><channel><title>Answers to: How to handle date format with SOAP web service in Ivy</title><link>https://answers.axonivy.com/questions/2062/how-to-handle-date-format-with-soap-web-service-in-ivy</link><description>&lt;p&gt;Hi Everyone,&lt;/p&gt;
&lt;p&gt;Now, I got the trouble with format date in SOAP webservice which created by Ivy&lt;/p&gt;
&lt;p&gt;&lt;img alt="alt text" src="http://answers.axonivy.com/upfiles/SoapWS_DateError_Ivy_FIwnKbB.png"&gt;&lt;/p&gt;
&lt;p&gt;When I call it by SOAP client, I always got the exception like &lt;strong&gt;Unmarshalling Error: 28.08.2016&lt;/strong&gt;
Because as we know, the expected format for date in XML is: YYYY-MM-DDThh:mm:ss. But I want to use the custom format like dd.MM.YYYY&lt;/p&gt;
&lt;p&gt;Do you have any ideas about that?&lt;/p&gt;
&lt;p&gt;Regards&lt;/p&gt;</description><atom:link href="https://answers.axonivy.com/questions/2062/how-to-handle-date-format-with-soap-web-service-in-ivy" rel="self"></atom:link><language>en</language><lastBuildDate>Mon, 03 Oct 2016 13:41:03 -0400</lastBuildDate><item><title>Answer by Reguel Wermelinger</title><link>https://answers.axonivy.com/questions/2062/how-to-handle-date-format-with-soap-web-service-in-ivy/2069</link><description>&lt;p&gt;You can implement a custom adapter that parses your special date format string into a valid date. &lt;/p&gt;
&lt;pre&gt;&lt;code&gt;package xmlhelper;

import java.text.SimpleDateFormat;
import java.util.Date;

import javax.xml.bind.annotation.adapters.XmlAdapter;

public class DateAdapter extends XmlAdapter&amp;lt;String, Date&amp;gt; {

    private SimpleDateFormat dateFormat = new SimpleDateFormat("dd.MM.yyyy");

    @Override
    public String marshal(Date v) throws Exception {
        return dateFormat.format(v);
    }

    @Override
    public Date unmarshal(String v) throws Exception {
        return dateFormat.parse(v);
    }
}
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;To use it in your webservice you have to modify the generated webservice source class. Simply add an &lt;code&gt;@XmlJavaTypeAdapter&lt;/code&gt; annotation into your method parameter definiton:&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;  @javax.jws.WebMethod
  @javax.jws.WebResult(name="result")
  public CallResult call(
          @javax.jws.WebParam(name="createJavaDataSaved") 
          @XmlJavaTypeAdapter(DateAdapter.class) 
          java.util.Date createJavaDataSaved)
    throws ch.ivyteam.ivy.webservice.process.restricted.WebServiceProcessTechnicalException
  {
    ...
  }
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;Remember that the generated webservice source will be overwritten whenever you change the mod file of the webservice. So you should at least write a test against your webservice stub so that you get an early warning if the adapter is not in charge anymore.&lt;/p&gt;
&lt;p&gt;&lt;img alt="alt text" src="https://answers.axonivy.com/upfiles/soapUiCallWithSpecialDateFormat.png"&gt;
You can inspect a full sample implementation here: &lt;a href="/upfiles/webserviceProviderWithSpecialDateFormat_63.iar"&gt;webserviceProviderWithSpecialDateFormat_63.iar&lt;/a&gt;&lt;/p&gt;</description><dc:creator xmlns:dc="http://purl.org/dc/elements/1.1/">Reguel Wermelinger</dc:creator><pubDate>Mon, 03 Oct 2016 13:41:03 -0400</pubDate><guid>https://answers.axonivy.com/questions/2062/how-to-handle-date-format-with-soap-web-service-in-ivy/2069</guid></item></channel></rss>