JAX-RS改变了json序列化器 [英] JAX-RS change json serializer
本文介绍了JAX-RS改变了json序列化器的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想将我的序列化程序更改为jackson,所以我可以更改时间戳格式,我试过这样:
I want to change my serializer to jackson, so I could change timestamp format, i tried like this:
@Provider
@Produces(MediaType.APPLICATION_JSON)
public class JacksonConfig
implements ContextResolver<ObjectMapper> {
private final ObjectMapper objectMapper;
public JacksonConfig() {
objectMapper = new ObjectMapper();
objectMapper.setDateFormat(new ISO8601DateFormat());
objectMapper.configure(SerializationFeature.WRITE_DATES_AS_TIMESTAMPS,
false);
}
@Override
public ObjectMapper getContext(Class<?> objectType) {
return objectMapper;
}
}
和ApplicationConfig:
and in ApplicationConfig :
resources.add(com.rfid.server.helpers.JacksonConfig.class);
它不起作用,我的时间戳格式仍然如下: 2014-12- 12T17:52:33.35031 + 02:00
It didn't work, I still get timestamps formatted like his: 2014-12-12T17:52:33.35031+02:00"
我试过调试 JacksonConfig
,断点来了构造函数,但不是 getContext
方法
I tried debugging JacksonConfig
, breakpoint comes to the constructor, but not getContext
method
推荐答案
@aribeiro评论似乎没关系。你只需要根据你的要求改变数据格式。
The @aribeiro comment seems to be ok. You just have to change the data format according to your requirements.
确保你的项目中有以下依赖项:
Make sure you have the following dependency in your project:
<dependency>
<groupId>org.codehaus.jackson</groupId>
<artifactId>jackson-jaxrs</artifactId>
<version>1.9.13</version>
</dependency>
这篇关于JAX-RS改变了json序列化器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文