I need to use Jackson to marshal and unmarshal json on arbitrary objects, and I need a certain date format.
Right now, I have this:
final ObjectMapper mapper = new ObjectMapper()
mapper.configure(JsonParser.Feature.ALLOW_UNQUOTED_FIELD_NAMES, true)
mapper.configure(JsonParser.Feature.ALLOW_SINGLE_QUOTES, true)
When I run mapper.writeValueAsString([a:new Date()]), I get a timestamp. My previous marshaling solution used this:
ISODateTimeFormat.dateTime().withZoneUTC().print(it.getTime())
but I can only seem to find a way to set a specific marshaller in Jackson with annotations. I have multiple classes for which I need particular marshaling, none of which can be annotated. Is there a way to set up marshaler by class?
Create a module, and add serializers to it for each type.