Very puzzling...your parse and print methods should not be ignored, unless you're somehow identifying them incorrectly in the binding file. Perhaps(?) when Kohsuke wrote that in 2006, you may have needed to manually create your own parse functions...but that is such a common request today perhaps JAXB creates that adapter class for you automatically now, and for some reason your override is not being activated?
At any rate, doesn't matter, if you search on "Q: How to map xsd:dateTime to java.util.Date?" on this page: http://cxf.apache.org/docs/wsdl-to-java.html, you'll see CXF has its own internal classes you can use for that conversion. Apparently you'll need to place this configuration in a JAX-WS binding file and not a JAXB one. HTH, Glen Bruno Dusausoy wrote: > > Hi, > > I've read Kohsuke's blog in order to map xs:date to java.util.Date[1] > > Its solution is working well but one thing is annoying. > When launching the code generation from cxf-codegen-plugin, one class is > created : org.w3._2001.xmlschema.Adapter1. > > Its content is : > > package org.w3._2001.xmlschema; > > import java.util.Date; > import javax.xml.bind.annotation.adapters.XmlAdapter; > > public class Adapter1 > extends XmlAdapter<String, Date> > { > public Date unmarshal(String value) { > return > (be.ucm.career.converter.jaxb.DateAdapter.parseDate(value)); > } > > public String marshal(Date value) { > return > (be.ucm.career.converter.jaxb.DateAdapter.printDate(value)); > } > > } > > Note the ugly class and package names. > I don't understand the use of this class since I've created my own > adapter, just like Kohsuke did : > > package be.ucm.career.converter.jaxb; > > import javax.xml.bind.DatatypeConverter; > import java.util.Calendar; > import java.util.Date; > import java.util.GregorianCalendar; > > public class DateAdapter { > > public static Date parseDate(String s) { > return DatatypeConverter.parseDate(s).getTime(); > } > > public static String printDate(Date dt) { > Calendar cal = new GregorianCalendar(); > cal.setTime(dt); > return DatatypeConverter.printDate(cal); > } > > } > > and added the corresponding binding option : > > <?xml version="1.0" encoding="UTF-8" standalone="yes"?> > <jaxb:bindings version="2.0" > xmlns:jaxb="http://java.sun.com/xml/ns/jaxb" > xmlns:xjc="http://java.sun.com/xml/ns/jaxb/xjc" > xmlns:xs="http://www.w3.org/2001/XMLSchema" > xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/"> > <jaxb:globalBindings localScoping="nested" > collectionType="java.util.ArrayList" > generateValueClass="true"> > <jaxb:javaType name="java.util.Date" > xmlType="xs:date" > parseMethod="be.ucm.career.converter.jaxb.DateAdapter.parseDate" > > printMethod="be.ucm.career.converter.jaxb.DateAdapter.printDate" > hasNsContext="false" /> > <xjc:serializable uid="2"/> > </jaxb:globalBindings> > </jaxb:bindings> > > So normally it should only use my class and not creating one. > Moreover the generated code uses the new class, like this : > > @XmlElement(name = "CreationDate", required = true, type = > String.class) > @XmlJavaTypeAdapter(Adapter1 .class) > @XmlSchemaType(name = "date") > protected Date creationDate; > > Is there something I missed ? > > Regards. > > [1] > http://weblogs.java.net/blog/kohsuke/archive/2006/03/how_do_i_map_xs.html > -- > Bruno Dusausoy > YP5 Software > -- > Pensez environnement : limitez l'impression de ce mail. > Please don't print this e-mail unless you really need to. > > -- View this message in context: http://cxf.547215.n5.nabble.com/JAXB-bindings-and-xs-date-to-java-util-Date-conversion-tp2143517p2218760.html Sent from the cxf-user mailing list archive at Nabble.com.
