How do I get Jackson to serialize my Joda DateTime object according to a simple pattern (like "dd-MM-yyyy")?
I've tried:
@JsonSerialize(using=DateTimeSerializer.class)
private final DateTime date;
I've also tried:
ObjectMapper mapper = new ObjectMapper()
.getSerializationConfig()
.setDateFormat(df);
Thanks!
This has become very easy with Jackson 2.0 and the Joda module.
ObjectMapper mapper = new ObjectMapper();
mapper.registerModule(new JodaModule());
Maven dependency:
<dependency>
<groupId>com.fasterxml.jackson.datatype</groupId>
<artifactId>jackson-datatype-joda</artifactId>
<version>2.1.1</version>
</dependency>
Code and documentation: https://github.com/FasterXML/jackson-datatype-joda
Binaries: http://repo1.maven.org/maven2/com/fasterxml/jackson/datatype/jackson-datatype-joda/