org.openapitools.jackson.nullable.JsonNullableBeanPropertyWriter 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.core.JsonGenerator;
import com.fasterxml.jackson.databind.PropertyName;
import com.fasterxml.jackson.databind.SerializerProvider;
import com.fasterxml.jackson.databind.ser.BeanPropertyWriter;
import com.fasterxml.jackson.databind.util.NameTransformer;
public class JsonNullableBeanPropertyWriter extends BeanPropertyWriter
{
private static final long serialVersionUID = 1L;
protected JsonNullableBeanPropertyWriter(BeanPropertyWriter base) {
super(base);
}
protected JsonNullableBeanPropertyWriter(BeanPropertyWriter base, PropertyName newName) {
super(base, newName);
}
@Override
protected BeanPropertyWriter _new(PropertyName newName) {
return new JsonNullableBeanPropertyWriter(this, newName);
}
@Override
public BeanPropertyWriter unwrappingWriter(NameTransformer unwrapper) {
return new UnwrappingJsonNullableBeanPropertyWriter(this, unwrapper);
}
@Override
public void serializeAsField(Object bean, JsonGenerator jgen, SerializerProvider prov) throws Exception
{
Object value = get(bean);
if (JsonNullable.undefined().equals(value) || (_nullSerializer == null && value == null)) {
return;
}
super.serializeAsField(bean, jgen, prov);
}
}
© 2015 - 2024 Weber Informatics LLC | Privacy Policy