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

org.zapodot.jackson.java8.JavaOptionalBeanPropertyWriter Maven / Gradle / Ivy

Go to download

Jackson Databind module for serializing and deserializing Java 8 java.util.Option objects. This tool is forked from original source created by @realjenius

There is a newer version: 2.6.1
Show newest version
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