All Downloads are FREE. Search and download functionalities are using the official Maven repository.

restx.jackson.FrontObjectMapperCustomizer Maven / Gradle / Ivy

The newest version!
package restx.jackson;

import com.fasterxml.jackson.databind.JsonDeserializer;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.databind.introspect.Annotated;
import com.fasterxml.jackson.databind.introspect.JacksonAnnotationIntrospector;
import org.jongo.marshall.jackson.oid.ObjectIdDeserializer;
import org.jongo.marshall.jackson.oid.ObjectIdSerializer;
import restx.factory.Component;
import restx.factory.NamedComponent;
import restx.factory.SingleComponentNameCustomizerEngine;

/**
 * User: xavierhanin
 * Date: 3/30/13
 * Time: 5:27 PM
 */
@Component
public class FrontObjectMapperCustomizer extends SingleComponentNameCustomizerEngine {
    public FrontObjectMapperCustomizer() {
        super(0, FrontObjectMapperFactory.NAME);
    }

    @Override
    public NamedComponent customize(NamedComponent namedComponent) {
        customize(namedComponent.getComponent());
        return namedComponent;
    }

    public void customize(ObjectMapper mapper) {
        mapper.setAnnotationIntrospector(new JacksonAnnotationIntrospector() {
            @Override
            public Object findSerializer(Annotated am) {
                Object serializer = super.findSerializer(am);
                if (ObjectIdSerializer.class == serializer
                        || FixedPrecisionSerializer.class == serializer) {
                    return null;
                }
                return serializer;
            }

            @Override
            public Class> findDeserializer(Annotated a) {
                Class> deserializer = (Class>) super.findDeserializer(a);
                if (ObjectIdDeserializer.class == deserializer
                        || FixedPrecisionDeserializer.class == deserializer) {
                    return null;
                }
                return deserializer;
            }
        });
    }
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy