org.zapodot.jackson.java8.JavaOptionalBeanPropertyWriter Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of jackson-databind-java-optional Show documentation
Show all versions of jackson-databind-java-optional Show documentation
Jackson Databind module for serializing and deserializing Java 8 java.util.Option objects.
This tool is forked from original source created by @realjenius
package org.zapodot.jackson.java8;
import com.fasterxml.jackson.core.JsonGenerator;
import com.fasterxml.jackson.databind.SerializerProvider;
import com.fasterxml.jackson.databind.ser.BeanPropertyWriter;
import java.util.Optional;
/**
* @author R.J. Lorimer [[email protected]]
*/
public class JavaOptionalBeanPropertyWriter extends BeanPropertyWriter {
protected JavaOptionalBeanPropertyWriter(BeanPropertyWriter base) {
super(base);
}
@Override
public void serializeAsField(Object bean, JsonGenerator jgen, SerializerProvider prov) throws Exception {
Object val = get(bean);
if((val == null || Optional.empty().equals(val)) && _nullSerializer == null) {
return;
}
super.serializeAsField(bean, jgen, prov);
}
}
© 2015 - 2024 Weber Informatics LLC | Privacy Policy