JavaJaxRS.resteasy.eap.JacksonConfig.mustache Maven / Gradle / Ivy
package {{invokerPackage}};
import {{javaxPackage}}.ws.rs.Produces;
import {{javaxPackage}}.ws.rs.core.MediaType;
import {{javaxPackage}}.ws.rs.ext.ContextResolver;
import {{javaxPackage}}.ws.rs.ext.Provider;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.datatype.jsr310.JavaTimeModule;
@Provider
@Produces(MediaType.APPLICATION_JSON)
public class JacksonConfig implements ContextResolver {
private static final Logger LOG = LoggerFactory.getLogger(JacksonConfig.class);
private ObjectMapper objectMapper;
public JacksonConfig() throws Exception {
this.objectMapper = new ObjectMapper();
this.objectMapper.registerModule(new JavaTimeModule());
// sample to convert any DateTime to readable timestamps
//this.objectMapper.configure(SerializationFeature.WRITE_DATES_AS_TIMESTAMPS, true);
}
public ObjectMapper getContext(Class> objectType) {
return objectMapper;
}
}