Date conversation error during jaxb marshall on a JPA object using eclipselink

I stuck on this Date conversation error for quite some time ... I am using eclipselinks, openJPA under TomcatEE environment, and trying to use jaxb doing marshalling. I met a problem for marshall one JPA object, which contains Date, TimeStamp elements. The exception message is ---

javax.xml.bind.MarshalException - with linked exception: [Exception [EclipseLink-3002] (Eclipse Persistence Services - 2.3.2.v20111125-r10461): org.eclipse.persistence.exceptions.ConversionException Exception Description: The object [3/19/12 12:00 AM], of class [class$util$Date$proxy], from mapping [org.eclipse.persistence.oxm.mappings.XMLDirectMapping[createTs-->createTs/text()]] with descriptor [XMLDescriptor( --> [])], could not be converted to [class java.util.Date].]

The strange thing is jaxb converting works OK for some customers, but not some other customer. I tried to put @XmlElement(type=Date.class) for this field crtTs, It doesn't work.

Thanks for your help in advance.



I have been able to reproduce the issue you are seeing. You can use the following bug to track our progress on this issue:



You could use an XmlAdapter to convert the problematic date into a proper java.util.Date.

package forum11145711;

import java.util.Date;
import javax.xml.bind.annotation.adapters.XmlAdapter;

public class DateAdapter extends XmlAdapter<Date, Date>{

    public Date unmarshal(Date date) throws Exception {
        return date;

    public Date marshal(Date date) throws Exception {
        if(null == date) {
            return date;
        return new Date(date.getTime());



The @XmlJavaTypeAdapter annotation is used to leverage the XmlAdapter:

package forum11145711;

import java.util.Date;
import javax.xml.bind.annotation.XmlRootElement;
import javax.xml.bind.annotation.adapters.XmlJavaTypeAdapter;

public class Root {

    private Date date;

    public Date getDate() {
        return date;

    public void setDate(Date date) { = date;



Below is the subclass of java.util.Date I'm using in this example.

package forum11145711;

import java.util.Date;

public class MyDate extends Date {



Below is some demo code you can use to prove that everything works:

package forum11145711;

import javax.xml.bind.JAXBContext;
import javax.xml.bind.Marshaller;

public class Demo {

    public static void main(String[] args) throws Exception {
        JAXBContext jc = JAXBContext.newInstance(Root.class);

        Root root = new Root();
        root.setDate(new MyDate());

        Marshaller marshaller = jc.createMarshaller();
        marshaller.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, true);
        marshaller.marshal(root, System.out);



<?xml version="1.0" encoding="UTF-8"?>

Need Your Help

OOP: Designing a menu system

objective-c model-view-controller oop

I am currently trying to create a menu system for a game and cannot arrive at any really sound way to do it. There are several menu screens, each of them non-trivial, so that I would like to keep t...

WPF - Drawing on canvas with mouse events

c# wpf wpf-controls

I have a problem with handling mouse events on canvas. I want to draw on it using mouse and I've come up with these event handlers, but they don't do anything when I start drawing.