[jboss-jira] [JBoss JIRA] (AS7-4334) RESTeasy: Cannot configure Jackson ObjectMapper via ContextResolver nor Application.getSingletons()
Hendy Irawan (JIRA)
jira-events at lists.jboss.org
Thu Mar 29 14:24:47 EDT 2012
[ https://issues.jboss.org/browse/AS7-4334?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]
Hendy Irawan updated AS7-4334:
------------------------------
Description:
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.
was:
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
Bug is almost similar to #AS7-1408.
> 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
More information about the jboss-jira
mailing list