jax rs应用程序在was liberty中不返回以毫秒为单位的日期

p4tfgftt  于 2021-06-27  发布在  Java
关注(0)|答案(1)|浏览(355)

下午好,我创建了一个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;
    }
 }

并将这个类添加到我的应用程序中,但它似乎不起作用。我怀疑我可能误解了什么……;)

dba5bblo

dba5bblo1#

正如paulsamsotha所建议的,注册jacksonjaxbjsonprovider.class就足够了
谢谢

相关问题