org.zapodot.jackson.java8.JavaOptionalBeanSerializerModifier 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.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());
}
}