zapodot / jackson-databind-java-optional Goto Github PK
View Code? Open in Web Editor NEWThis project forked from realjenius/jackson-databind-java8
A shim library to support mapping Java8 Optionals through Jackson.
License: Other
This project forked from realjenius/jackson-databind-java8
A shim library to support mapping Java8 Optionals through Jackson.
License: Other
I have set my ObjectMapper to ignore null values using
objectMapper.setSerializationInclusion(JsonInclude.Include.NON_NULL);
so it wouldn't generate unnecessary "myObject" = null
.
This module(which I'm using via dropwizard) ignores the inclusion setting and serializes null. I was wondering if it'd be possible for this module to not ignore it.
Please install our new product, Sonatype Lift with advanced features
If it works, can you release it to Maven Central, please?
Vulnerabilities
DepShield reports that this application's usage of com.fasterxml.jackson.core:jackson-databind:2.6.1 results in the following vulnerability(s):
This is an automated GitHub Issue created by Sonatype DepShield. Details on managing GitHub Apps, including DepShield, are available for personal and organization accounts. Please submit questions or feedback about DepShield to the Sonatype DepShield Community.
Hi. Here are minimal example.
public class JavaOptionalModuleTest {
public class Inner {
@Override
public boolean equals(Object o) {
if (this == o) return true;
if (o == null || getClass() != o.getClass()) return false;
Inner inner = (Inner) o;
return integer.equals(inner.integer);
}
public Inner() {
}
public Inner(Optional<Integer> integer) {
this.integer = integer;
}
@Override
public int hashCode() {
return integer.hashCode();
}
@JsonProperty
public Optional<Integer> integer = Optional.empty();
}
public class OptionalContaining {
public OptionalContaining() {
}
public OptionalContaining(Optional<Inner> inner) {
this.inner = inner;
}
@JsonProperty
public Optional<Inner> inner = Optional.empty();
@Override
public boolean equals(Object o) {
if (this == o) return true;
if (o == null || getClass() != o.getClass()) return false;
OptionalContaining that = (OptionalContaining) o;
return inner.equals(that.inner);
}
@Override
public int hashCode() {
return inner.hashCode();
}
}
@Test
public void testDeserialization() throws IOException {
ObjectMapper mapper = new ObjectMapper().registerModule(new JavaOptionalModule());
mapper.setVisibility(PropertyAccessor.FIELD, JsonAutoDetect.Visibility.ANY);
mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
assertEquals(new OptionalContaining(Optional.of(new Inner(Optional.of(7)))),
mapper.readValue("{\"inner\":{\"integer\":7}}", OptionalContaining.class));
}
}
I get an exception.
com.fasterxml.jackson.databind.JsonMappingException: No suitable constructor found for type [simple type, class com.zeptolab.zombies.commons.JavaOptionalModuleTest$OptionalContaining]: can not instantiate from JSON object (need to add/enable type information?)
at [Source: java.io.StringReader@6e20b53a; line: 1, column: 2]
at com.fasterxml.jackson.databind.JsonMappingException.from(JsonMappingException.java:164)
at com.fasterxml.jackson.databind.deser.BeanDeserializerBase.deserializeFromObjectUsingNonDefault(BeanDeserializerBase.java:1078)
at com.fasterxml.jackson.databind.deser.BeanDeserializer.deserializeFromObject(BeanDeserializer.java:268)
at com.fasterxml.jackson.databind.deser.BeanDeserializer.deserialize(BeanDeserializer.java:124)
at com.fasterxml.jackson.databind.ObjectMapper._readMapAndClose(ObjectMapper.java:2993)
at com.fasterxml.jackson.databind.ObjectMapper.readValue(ObjectMapper.java:2098)
at com.zeptolab.zombies.commons.JavaOptionalModuleTest.testDeserialization(JavaOptionalModuleTest.java:88)
What I'm doing wrong?
Edward.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.