Search in sources :

Example 1 with HidableSerializer

use of com.baeldung.jackson.dynamicIgnore.HidableSerializer in project tutorials by eugenp.

the class JacksonDynamicIgnoreUnitTest method setUp.

@Before
public void setUp() {
    mapper.setSerializationInclusion(Include.NON_EMPTY);
    mapper.registerModule(new SimpleModule() {

        @Override
        public void setupModule(final SetupContext context) {
            super.setupModule(context);
            context.addBeanSerializerModifier(new BeanSerializerModifier() {

                @Override
                public JsonSerializer<?> modifySerializer(final SerializationConfig config, final BeanDescription beanDesc, final JsonSerializer<?> serializer) {
                    if (Hidable.class.isAssignableFrom(beanDesc.getBeanClass())) {
                        return new HidableSerializer((JsonSerializer<Object>) serializer);
                    }
                    return serializer;
                }
            });
        }
    });
}
Also used : HidableSerializer(com.baeldung.jackson.dynamicIgnore.HidableSerializer) SerializationConfig(com.fasterxml.jackson.databind.SerializationConfig) BeanDescription(com.fasterxml.jackson.databind.BeanDescription) JsonSerializer(com.fasterxml.jackson.databind.JsonSerializer) SimpleModule(com.fasterxml.jackson.databind.module.SimpleModule) BeanSerializerModifier(com.fasterxml.jackson.databind.ser.BeanSerializerModifier) Before(org.junit.Before)

Aggregations

HidableSerializer (com.baeldung.jackson.dynamicIgnore.HidableSerializer)1 BeanDescription (com.fasterxml.jackson.databind.BeanDescription)1 JsonSerializer (com.fasterxml.jackson.databind.JsonSerializer)1 SerializationConfig (com.fasterxml.jackson.databind.SerializationConfig)1 SimpleModule (com.fasterxml.jackson.databind.module.SimpleModule)1 BeanSerializerModifier (com.fasterxml.jackson.databind.ser.BeanSerializerModifier)1 Before (org.junit.Before)1