Jackson 有很多序列化选项。在您的情况下,您需要设置:
private ObjectMapper mapper = new ObjectMapper();
mapper.configure(SerializationConfig.Feature.WRITE_DATES_AS_TIMESTAMPS, false);
如果您使用的是 Jackson 1.x 或
private ObjectMapper mapper = new ObjectMapper();
mapper.configure(SerializationFeature.WRITE_DATES_AS_TIMESTAMPS, false);
如果您使用的是 Jackson 2.x。
要允许 Jersey 访问您的自定义ObjectMapper
,您需要创建一个提供程序:
@Provider
public class ObjectMapperProvider implements ContextResolver<ObjectMapper>
{
private final transient ObjectMapper mapper;
@Inject
public ObjectMapperProvider()
{
this.mapper = MyMapper.getMapper();
}
@Override
public ObjectMapper getContext(final Class<?> type)
{
return this.mapper;
}
}
在哪里MyMapper.getMapper()
返回您的自定义ObjectMapper
。