下午好,我创建了一个javax.ws.rs.core.application,它用wildfly以毫秒为单位返回日期对象。由于我最近不得不切换到ibmwebsphereliberty,我注意到现在日期是以时间戳格式返回的。我尝试添加此contextresolver:
@Provider
@Produces("application/json")
public class JacksonConfig implements ContextResolver<ObjectMapper>
{
private ObjectMapper mapper = new ObjectMapper();
public JacksonConfig() throws Exception
{
SerializationConfig serConfig = mapper.getSerializationConfig();
serConfig.setDateFormat(new SimpleDateFormat("dd-MMM-yyyy"));
DeserializationConfig deserializationConfig = mapper.getDeserializationConfig();
deserializationConfig.setDateFormat(new SimpleDateFormat("dd-MMM-yyyy"));
mapper.configure(SerializationConfig.Feature.WRITE_DATES_AS_TIMESTAMPS, false); }
@Override
public ObjectMapper getContext(Class<?> arg0)
{
return mapper;
}
}
并将这个类添加到我的应用程序中,但它似乎不起作用。我怀疑我可能误解了什么……;)
1条答案
按热度按时间dba5bblo1#
正如paulsamsotha所建议的,注册jacksonjaxbjsonprovider.class就足够了
谢谢