[
https://issues.jboss.org/browse/AS7-4334?page=com.atlassian.jira.plugin.s...
]
Hendy Irawan commented on AS7-4334:
-----------------------------------
Just for fun, I tried running the sample project app on OpenShift here :
http://earsample-ecommerce.rhcloud.com/api/article/
And surprisingly, it works !!!
Then I restarted my local JBoss instance and voila, it works !
Something fishy is going on with the classloading or something... (I tried to undeploy the
app and redeploy, and didn't work) but at least now I'm happy it works after
restarting JBoss.
For the status of this bug, I'll leave it to you. Probably good as a documentation for
other people who stumbled on to this bug. The workaround: just restart JBoss.
RESTeasy: Cannot configure Jackson ObjectMapper via ContextResolver
nor Application.getSingletons()
---------------------------------------------------------------------------------------------------
Key: AS7-4334
URL:
https://issues.jboss.org/browse/AS7-4334
Project: Application Server 7
Issue Type: Bug
Components: REST
Affects Versions: 7.1.1.Final
Environment: JBoss AS 7.1.1
Reporter: Hendy Irawan
Assignee: Stuart Douglas
This doesn't work:
{code}
@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;
}
}
{code}
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:
{code}
@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;
}
{code}
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.
--
This message is automatically generated by JIRA.
If you think it was sent incorrectly, please contact your JIRA administrators:
https://issues.jboss.org/secure/ContactAdministrators!default.jspa
For more information on JIRA, see:
http://www.atlassian.com/software/jira