org.openapitools.jackson.nullable.JsonNullableBeanSerializerModifier Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of jackson-databind-nullable Show documentation
Show all versions of jackson-databind-nullable Show documentation
JsonNullable wrapper class and Jackson module to support fields with meaningful null values.
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;
}
}