1

So I've got my Jackson and Joda support all set up...

ext.jackson = [version: '2.3.2']
...
compile "com.fasterxml.jackson.core:jackson-core:${jackson.version}"
compile "com.fasterxml.jackson.core:jackson-databind:${jackson.version}"
compile "com.fasterxml.jackson.core:jackson-annotations:${jackson.version}"
compile "com.fasterxml.jackson.datatype:jackson-datatype-joda:${jackson.version}"

And my OjbectMapper configured to use the JodaModule() to format java.util.Dates

private static final ObjectMapper mapper = new ObjectMapper();
static {
    // JodaModule gets Dates handled as ISO-8601 strings
    JodaModule jodaModule = new JodaModule();
    mapper.registerModule( jodaModule );
    mapper.configure( SerializationFeature.WRITE_DATES_AS_TIMESTAMPS, false );
}

But I can't figure out how to get the JodaModlue to format the java.util.Date occurrences in my POJOs like "2014-02-07T21:29:19.032Z" rather than "2014-02-07T21:29:19.032+0000". When I do this "stand-alone" in Joda the incantation is ISODateTimeFormat.dateTime().withZoneUTC(). How can I jack that DateTimeFormatter into the JodaModule() I push into the ObjectMapper?

Bob Kuhar
  • 10,838
  • 11
  • 62
  • 115

1 Answers1

1

In theory, use of annotation @JsonFormat(pattern="..."), but I think this improvement (make Joda module datatypes recognize and use @JsonFormat) is only going to be included in 2.4.0. But once that happens it will be available (it already works for JDK date/time types, FWIW).

But you may want to file a feature request (issue at github tracker) for Joda module, to specifically request a simple feature for Joda module for "optimizing" output of UTZ timezone.

StaxMan
  • 113,358
  • 34
  • 211
  • 239
  • I might go the "issue tracker" path. Thanks for the suggestion. In the interim, what I discovered is that I do get the "2014-02-07T21:29:19.032Z" output if my POJO doesn't use java.util.Date but, rather, org.joda.time.DateTime. I'm leaning towards this as the correct answer for my question; you can't get there from java.util.Date, but leverage org.joda.time.DateTime and you are golden. – Bob Kuhar Mar 28 '14 at 22:38