cannot use custom object mapper for single objects in jersey (works for collections)

169 views Asked by At

I'm using the latest release of Jersey (2.13) on a glassfish server together with the latest version of jackson (version. 2.4) . I've written and registered a custom ObjectMapper, but it only collections seems to be serialized by my custom objectmapper.

I've seen a similar issue at this page: https://java.net/jira/browse/GLASSFISH-20815 but the workaround presented there did not work for me.

My jersey mapper provider class:

@Provider public class JerseyMapperProvider implements 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;
}

...

1

There are 1 answers

0
Nolf On BEST ANSWER

okay, suddenly it worked by adding the following features to my resourceConfig...

@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..

}
}