Himanshu Yadav Himanshu Yadav - 1 year ago 126
Java Question

Jackson does not support ISO date format

Writing a web service which supports both Xml and JSON media types. Following ISO standard to support date format


To support this format in xml I have written a
class which takes carecof marshaling and un-marshaling of date fields.

There is a CustomSerialization and Deserialization class for Json formats. It's implementation is almost similar to Adapter class. But it throws exception.

public void serialize(Date aDate, JsonGenerator aJsonGenerator, SerializerProvider aSerializerProvider)
throws IOException, JsonProcessingException {

SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSSXXX");
String dateString = dateFormat.format(aDate);


Illegal pattern character 'X'
at java.text.SimpleDateFormat.compile(SimpleDateFormat.java:768)

Using jackson v2.2.1
Working Adapter implementation is exactly same.

private SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSSXXX");

public String marshal(final Date v) throws Exception {
return dateFormat.format(v);

public Date unmarshal(final String v) throws Exception {
return dateFormat.parse(v);

Answer Source

Joop Eggen's comment fixed the issue. Simple Date Format from SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSSXXX"); to SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSSZ"); fixed the issue.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download