I have a simple xml string like this
I have a pojo class for xml strings like this
@XmlRootElement(name="test")
public class Test {
@XmlElement
public String test_id;
@XmlElement
public Date dateprix;
@XmlElement
public String nomtest;
@XmlElement
public double prixtest;
@XmlElement
public char webposted;
@XmlElement
public Date posteddate;
}
I use jaxb for xml to bind to java objects. The code is
try {
Test t = new Test
JAXBContext jaxbContext = JAXBContext.newInstance(t.getClass());
Unmarshaller jaxbUnmarshaller = jaxbContext.createUnmarshaller();
t = (Test) jaxbUnmarshaller.unmarshal(new InputSource (new StringReader(xml))); // xml variable contain the xml string define above
} catch (JAXBException e) {
e.printStackTrace();
}
< p>Now my question is, after binding with the java object, I get null for the date variables (dateprix and posteddata), then how can I get this value.
If I use “2013- 06-06” I got the data object but for “2013-06-06 21:51:42.252” I got null.
JAXB expects XML The date is xsd: date (yyyy-MM-dd) or xsd: dateTime format (yyyy-MM-ddTHH: mm: ss.sss). 2013-06-06 21:51:42.252 is not a valid dateTime format’T’ (Date/time separator) is missing. You need a custom XmlAdapter to make JAXB convert it to Java Date. For example,
class DateAdapter extends XmlAdapter{
DateFormat f = new SimpleDateFormat("yyy-MM-dd HH:mm:ss.SSS");
@Override
public Date unmarshal(String v) throws Exception {
return f.parse(v);
}
@Override
public String marshal(Date v) throws Exception {
return f.format(v);
}
}
class Type {
@XmlJavaTypeAdapter(DateAdapter.class)
public Date dateprix;
...
WordPress database error: [Table 'yf99682.wp_s6mz6tyggq_comments' doesn't exist]SELECT SQL_CALC_FOUND_ROWS wp_s6mz6tyggq_comments.comment_ID FROM wp_s6mz6tyggq_comments WHERE ( comment_approved = '1' ) AND comment_post_ID = 6024 ORDER BY wp_s6mz6tyggq_comments.comment_date_gmt ASC, wp_s6mz6tyggq_comments.comment_ID ASC