-
Bug
-
Resolution: Cannot Reproduce
-
Major
-
None
-
7.1.1.Final
-
None
This doesn't work:
@Provider @Produces(MediaType.APPLICATION_JSON) public class JacksonContextResolver implements ContextResolver<ObjectMapper> { private transient Logger log = LoggerFactory.getLogger(JacksonContextResolver.class); private ObjectMapper objectMapper; public JacksonContextResolver() throws JsonGenerationException, JsonMappingException, IOException { log.info("Using my own Jackson ObjectMapper"); objectMapper = new ObjectMapper(); objectMapper.configure(Feature.INDENT_OUTPUT, true); objectMapper.configure(Feature.WRITE_DATES_AS_TIMESTAMPS, false); objectMapper.configure(Feature.WRITE_DATE_KEYS_AS_TIMESTAMPS, false); log.info("Test date: {}", objectMapper.writeValueAsString(new DateTime())); log.info("Test pretty output: {}", objectMapper .writeValueAsString(new Article("Launching AksiMata", "AksiMata : Ada apa di sana?", "Webapp yang keren dan oke punya.", "Hendy Irawan"))); } @Override public ObjectMapper getContext(Class<?> type) { return objectMapper; } }
The log correctly tests the custom ObjectMapper works fine, however when returning the output, seems like it's still using the "default" ObjectMapper.
This also doesn't work:
@Override public Set<Object> getSingletons() { Set<Object> singletons = new HashSet<Object>(super.getSingletons()); ObjectMapper objectMapper = new ObjectMapper(); objectMapper.configure(Feature.INDENT_OUTPUT, true); objectMapper.configure(Feature.WRITE_DATES_AS_TIMESTAMPS, false); objectMapper.configure(Feature.WRITE_DATE_KEYS_AS_TIMESTAMPS, false); singletons.add(objectMapper); return singletons; }
Sample project to reproduce the issue is at:
https://github.com/soluvas/ear-sample/tarball/resteasy-jackson-bug
After deploy, check the output via:
http://localhost:8080/api/article/
Bug is almost similar to #AS7-1408.
- is related to
-
AS7-1408 Missing module-dependency breacks reconfiguring jackson ObjectMapper with using resteasy-jackson-provider
- Resolved