Package restx.jackson

Source Code of restx.jackson.FrontObjectMapperCustomizer

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<ObjectMapper> {
    public FrontObjectMapperCustomizer() {
        super(0, FrontObjectMapperFactory.NAME);
    }

    @Override
    public NamedComponent<ObjectMapper> customize(NamedComponent<ObjectMapper> 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<? extends JsonDeserializer<?>> findDeserializer(Annotated a) {
                Class<? extends JsonDeserializer<?>> deserializer = super.findDeserializer(a);
                if (ObjectIdDeserializer.class == deserializer
                        || FixedPrecisionDeserializer.class == deserializer) {
                    return null;
                }
                return deserializer;
            }
        });
    }
}
TOP

Related Classes of restx.jackson.FrontObjectMapperCustomizer

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.