org.zapodot.jackson.java8.JavaOptionalDeserializer 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.JsonParser;
import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.DeserializationContext;
import com.fasterxml.jackson.databind.JavaType;
import com.fasterxml.jackson.databind.deser.std.StdDeserializer;
import java.io.IOException;
import java.util.Optional;
/**
* @author R.J. Lorimer [[email protected]]
*/
public class JavaOptionalDeserializer extends StdDeserializer> {
private final JavaType _referenceType;
public JavaOptionalDeserializer(JavaType valueType) {
super(valueType);
_referenceType = valueType.containedType(0);
}
@Override
public Optional> getNullValue() {
return Optional.empty();
}
@Override
public Optional> deserialize(JsonParser jp, DeserializationContext ctxt) throws IOException, JsonProcessingException {
Object reference = ctxt.findRootValueDeserializer(_referenceType).deserialize(jp, ctxt);
return Optional.of(reference);
}
}
© 2015 - 2024 Weber Informatics LLC | Privacy Policy