我使用RESTEasy使用JSON序列化实现REST服务.目前,日期自1970年以来被序列化为毫秒.为了提高兼容性,我想将我的日期变为两种格式之一; 毫秒+时区偏移或ISO 8061.
似乎RESTEasy曾经使用Jettison进行JSON序列化,但是从我一直在阅读的内容中他们已经切换到杰克逊......所有这些都让google搜索得到了很好的帮助.
据我所知,我需要实现一个ContextResolver:
public class JacksonConfig impelments ContextResolver<ObjectMapper>
{
private final OBjectMapper objectMapper;
public JacksonConfig() throws Exception
{
objectMapper = new ObjectMapper.configure(
SerializationFeature.WRITE_DATE_AS_TIMESTAMPS, false);
}
@Override
public ObjectMapper getContext(Class<?> arg0)
{
return objectMapper;
}
}
Run Code Online (Sandbox Code Playgroud)
我无法找到的是,我该怎么做?我把它放在哪里?
所以更大的问题是,我是朝着正确的方向前进,我的假设是否正确?