Skip to content

Instantly share code, notes, and snippets.

@alexandreaquiles
Created February 5, 2016 20:18
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save alexandreaquiles/b00ca3fdb35e45f0c53d to your computer and use it in GitHub Desktop.
Save alexandreaquiles/b00ca3fdb35e45f0c53d to your computer and use it in GitHub Desktop.
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