blob: 915aee0e321c26362cc302997b00345dfabf1ea4 [file] [log] [blame]
package edu.psu.swe.scim.server.rest;
import javax.annotation.PostConstruct;
import javax.inject.Inject;
import javax.ws.rs.ext.ContextResolver;
import javax.ws.rs.ext.Provider;
import com.fasterxml.jackson.annotation.JsonInclude.Include;
import com.fasterxml.jackson.databind.AnnotationIntrospector;
import com.fasterxml.jackson.databind.DeserializationFeature;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.databind.introspect.AnnotationIntrospectorPair;
import com.fasterxml.jackson.databind.introspect.JacksonAnnotationIntrospector;
import com.fasterxml.jackson.databind.module.SimpleModule;
import com.fasterxml.jackson.module.jaxb.JaxbAnnotationIntrospector;
import com.fasterxml.jackson.module.jaxb.JaxbAnnotationModule;
import edu.psu.swe.scim.server.schema.Registry;
import edu.psu.swe.scim.spec.resources.ScimResource;
@Provider
public class ObjectMapperContextResolver implements ContextResolver<ObjectMapper> {
private final ObjectMapper objectMapper;
@Inject
Registry registry;
public ObjectMapperContextResolver() {
objectMapper = new ObjectMapper();
JaxbAnnotationModule jaxbAnnotationModule = new JaxbAnnotationModule();
objectMapper.registerModule(jaxbAnnotationModule);
objectMapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
AnnotationIntrospector jaxbIntrospector = new JaxbAnnotationIntrospector(objectMapper.getTypeFactory());
AnnotationIntrospector jacksonIntrospector = new JacksonAnnotationIntrospector();
AnnotationIntrospector pair = new AnnotationIntrospectorPair(jaxbIntrospector, jacksonIntrospector);
objectMapper.setAnnotationIntrospector(pair);
objectMapper.setSerializationInclusion(Include.NON_NULL);
}
@PostConstruct
protected void postConstruct() {
SimpleModule module = new SimpleModule();
module.addDeserializer(ScimResource.class, new ScimResourceDeserializer(this.registry, this.objectMapper));
this.objectMapper.registerModule(module);
}
@Override
public ObjectMapper getContext(Class<?> type) {
return objectMapper;
}
}