无法让jackson jsr 310在weblogic 12.2.1上工作

时间:2016-10-10 18:56:08

标签: java spring weblogic

我无法使用weblogic来处理java 8 LocalDate。我正在将一个spring boot项目部署到weblogic,其他一切正常。

如果我在tomcat嵌入式服务器上将应用程序作为spring启动应用程序启动,那么我当前的java时间模块配置是有效的,但是当我部署到weblogic时则不行。

这是我到目前为止所尝试的:

weblogic.xml中

<?xml version="1.0" encoding="UTF-8"?>
<weblogic-web-app>
    <weblogic-version>12.2.1</weblogic-version>
    <context-root>/</context-root>
    <container-descriptor>
        <prefer-application-packages>
            <package-name>org.slf4j.*</package-name>
            <package-name>org.apache.commons.*</package-name>
            <package-name>com.fasterxml.jackson.*</package-name>
            <package-name>org.codehaus.jackson.*</package-name>
        </prefer-application-packages>

        <prefer-application-resources>
            <resource-name>org/slf4j/impl/StaticLoggerBinder.class</resource-name>
        </prefer-application-resources>
    </container-descriptor>
</weblogic-web-app>

泽西岛配置

@Bean
public Jackson2ObjectMapperBuilder jacksonBuilder() {
    Jackson2ObjectMapperBuilder builder = new Jackson2ObjectMapperBuilder();
    builder.featuresToDisable(SerializationFeature.WRITE_DATES_AS_TIMESTAMPS);
    return builder;
}

我尝试过的另一个 Jersey配置

@Configuration
@ApplicationPath("/rest")
public class JerseyConfig extends ResourceConfig {
    public JerseyConfig() throws JsonProcessingException {
        register(JacksonFeature.class);
        register(JacksonMapperProvider.class);
        packages("my.path");
    }


    public static class JacksonMapperProvider implements ContextResolver<ObjectMapper> {
        @Override
        public ObjectMapper getContext(final Class<?> aClass) {
            final ObjectMapper objectMapper = new ObjectMapper();
            objectMapper.registerModule(new JavaTimeModule());
            objectMapper.disable(SerializationFeature.WRITE_DATES_AS_TIMESTAMPS);
            return objectMapper;
        }
    }
}

来自以下端点的预期结果(以及我使用tomcat运行时获得的输出)

@GET
@Path("test")
public LocalDate test() {
    return LocalDate.ofEpochDay(0);
}

是:

"1970-01-01"

在weblogic上我得到:

{"year":1970,"month":"JANUARY","monthValue":1,"dayOfMonth":1,"dayOfWeek":"THURSDAY","era":"CE","dayOfYear":1,"leapYear":false,"chronology":{"id":"ISO","calendarType":"iso8601"}}

0 个答案:

没有答案