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

org.zapodot.jackson.java8.JavaOptionalBeanSerializerModifier 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.databind.BeanDescription;
import com.fasterxml.jackson.databind.SerializationConfig;
import com.fasterxml.jackson.databind.ser.BeanPropertyWriter;
import com.fasterxml.jackson.databind.ser.BeanSerializerModifier;

import java.util.List;
import java.util.Optional;
import java.util.stream.Collectors;

/**
 * @author R.J. Lorimer [[email protected]]
 */
public class JavaOptionalBeanSerializerModifier extends BeanSerializerModifier {
    @Override
    public List changeProperties(SerializationConfig config, BeanDescription beanDesc, List beanProperties) {
        return beanProperties.stream().map((w) -> {
            BeanPropertyWriter mapping = w;
            if (Optional.class.isAssignableFrom(w.getPropertyType())) {
                mapping = new JavaOptionalBeanPropertyWriter(w);
            }
            return mapping;
        }).collect(Collectors.toList());
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy