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

org.openapitools.jackson.nullable.JsonNullableBeanSerializerModifier Maven / Gradle / Ivy

Go to download

JsonNullable wrapper class and Jackson module to support fields with meaningful null values.

There is a newer version: 0.2.6
Show newest version
package org.openapitools.jackson.nullable;

import com.fasterxml.jackson.databind.BeanDescription;
import com.fasterxml.jackson.databind.JavaType;
import com.fasterxml.jackson.databind.SerializationConfig;
import com.fasterxml.jackson.databind.ser.BeanPropertyWriter;
import com.fasterxml.jackson.databind.ser.BeanSerializerModifier;

import java.util.List;

public class JsonNullableBeanSerializerModifier  extends BeanSerializerModifier
{
    @Override
    public List changeProperties(SerializationConfig config,
                                                     BeanDescription beanDesc,
                                                     List beanProperties)
    {
        for (int i = 0; i < beanProperties.size(); ++i) {
            final BeanPropertyWriter writer = beanProperties.get(i);
            JavaType type = writer.getType();
            if (type.isTypeOrSubTypeOf(JsonNullable.class)) {
                beanProperties.set(i, new JsonNullableBeanPropertyWriter(writer));
            }
        }
        return beanProperties;
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy