2

I am using "Full Data Binding" in Jackson to deserialize a date in a JSON string.

The format these dates are coming is "EEE MMM dd HH:mm:ss zzz yyyy".

I'm using Jackson 1.8 and I cannot figure out how to configure the ObjectMapper so it would deserialize these Strings properly into JODA DateTime objects.

Snippet from the POJO:

private DateTime deliveryTime;

@JsonProperty("DeliveryTime")
public void setDeliveryTime(DateTime deliveryTime) {
    this.deliveryTime = deliveryTime;
}

@JsonProperty("DeliveryTime")
public DateTime getDeliveryTime() {
    return deliveryTime;
}

Thanks.

Iker Jimenez
  • 7,105
  • 9
  • 49
  • 46
  • 1
    See [this](http://stackoverflow.com/a/27102120/695459) for a better solution introduced in Jackson 2.0. – mikijov Sep 15 '15 at 12:12

1 Answers1

2

The simplest way to configure ObjectMapper to use specific date/time format is to call ObjectMapper.setDateFormat(...) method.

There are some preliminary plans in creating a new Joda datatype Jackson module, as that would make it much easier to add powerful new configuration; current challenge being that Jackson itself should not have hard (static) dependency to external libraries (as much as I like Joda personally!), which limits degree to which lib-specific configurability can work.

StaxMan
  • 113,358
  • 34
  • 211
  • 239
  • This has now been written! I've shown some example config at http://stackoverflow.com/a/14185077/125246 – paulcm Jan 06 '13 at 18:11