0

我在 glassfish 服务器上使用最新版本的 Jersey (2.13) 以及最新版本的 jackson (version. 2.4) 。我已经编写并注册了一个自定义 ObjectMapper,但我的自定义 objectmapper 似乎只对集合进行了序列化。

我在此页面上看到了类似的问题:https ://java.net/jira/browse/GLASSFISH-20815 但那里提出的解决方法对我不起作用。

我的球衣映射器提供者类:

@Provider 公共类 JerseyMapperProvider 实现 ContextResolver {

private static ObjectMapper apiMapper = null;

public JerseyMapperProvider() {
}

@Override
public ObjectMapper getContext(Class<?> type) {
    System.out.println(type.toString() + " this is only printed for collections...");
    if (apiMapper == null) {
        apiMapper = getDefaultObjectMapper();
    }
    return apiMapper;
}

...

4

1 回答 1

0

好吧,突然它通过向我的资源配置添加以下功能来工作......

@ApplicationPath("/")

public class JerseyConfig extends ResourceConfig {

public JerseyConfig() {
    super();
    Map<String, Object> map = new HashMap<>();
    map.put(CommonProperties.MOXY_JSON_FEATURE_DISABLE, true);
    map.put(CommonProperties.JSON_PROCESSING_FEATURE_DISABLE, true);
    addProperties(map);
    ....// more configuration here..

}
}
于 2014-11-12T11:51:15.660 回答