--- /dev/null
+package de.spring.webservices.binders;
+
+import java.text.DateFormat;
+import java.text.SimpleDateFormat;
+import java.util.Date;
+import java.util.TimeZone;
+
+import javax.xml.bind.annotation.adapters.XmlAdapter;
+
+
+public class XSDateTimeCustomBinder extends XmlAdapter<String, Date> {
+
+ @Override
+ public Date unmarshal(final String dateTime) throws Exception {
+ // X pattern just works from Java >= 1.7
+ final DateFormat formatter = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ssX");
+ formatter.setTimeZone(TimeZone.getTimeZone("Europe/Madrid"));
+
+ return formatter.parse(dateTime);
+ }
+
+ @Override
+ public String marshal(final Date dateTime) throws Exception {
+ // X pattern just works from Java >= 1.7
+ final DateFormat formatter = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ssX");
+ formatter.setTimeZone(TimeZone.getTimeZone("Europe/Madrid"));
+
+ return formatter.format(dateTime);
+ }
+}
xmlns:jaxb="http://java.sun.com/xml/ns/jaxb"
xmlns:inheritance="http://jaxb2-commons.dev.java.net/basic/inheritance"
xmlns:annox="http://annox.dev.java.net"
+ xmlns:xjc="http://java.sun.com/xml/ns/jaxb/xjc"
jaxb:version="2.1"
- jaxb:extensionBindingPrefixes="inheritance annox">
+ jaxb:extensionBindingPrefixes="xjc inheritance annox">
<!--
Se procesa con Xpath si quieres meter expresiones regulares y cosas así en teoría dependes de Xpath
<!-- The same applies to annotate. If you do not want or you may not modify your xsd files you can
modify instead this file with your custom binding :) -->
+ <!-- Custom xs:dateTime adapter -->
+ <jaxb:globalBindings>
+ <xjc:javaType adapter="de.spring.webservices.binders.XSDateTimeCustomBinder"
+ name="java.util.Date" xmlType="xs:dateTime" />
+ </jaxb:globalBindings>
+
</jaxb:bindings>
<xs:complexType>
<xs:all>
<xs:element name="data" type="xs:string" />
+ <xs:element name="exampleDate" type="xs:dateTime" />
</xs:all>
</xs:complexType>
</xs:element>
<xs:complexType>
<xs:all>
<xs:element name="data" type="xs:string" />
+ <xs:element name="exampleDate" type="xs:dateTime" />
</xs:all>
</xs:complexType>
</xs:element>