Create a gist now

Instantly share code, notes, and snippets.

What would you like to do?
Configurações necessárias para (de)serializar classes do pacote java.time com o Jackson 2.x em uma API implementada com JAX-RS 2. Testado com o Wildfly 8.2.0.Final.
@Provider
public class JacksonJavaTimeConfiguration implements ContextResolver<ObjectMapper> {
private final ObjectMapper mapper;
public JacksonJavaTimeConfiguration() {
mapper = new ObjectMapper();
mapper.registerModule(new JSR310Module());
mapper.configure(SerializationFeature.WRITE_DATES_AS_TIMESTAMPS, false);
}
@Override
public ObjectMapper getContext(Class<?> type) {
return mapper;
}
}
<dependency>
<groupId>com.fasterxml.jackson.datatype</groupId>
<artifactId>jackson-datatype-jsr310</artifactId>
<version>2.4.1</version>
</dependency>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment