Question

How would one unmarshall the following XML response with JAXB into a domain class:

<?xml version="1.0" encoding="UTF-8"?>
<time>2014-01-14T06:24:34+00:00</time>

My first instinct was to use something like (short version):

@XmlRootElement
public class Time {
    @XmlElement
    public Date time;
}

but I think JAXB then sees 2 elements with the Time name. I also tried without using the @XmlRootElement annotation, but to no avail.

Was it helpful?

Solution

Have you tried using @XmlValue instead of @XmlElement for the time field? After all, it is the value of the root element, rather than a sub-element.

I've now tried this with the file supplied, and it works properly.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top