Skip to content

Commit

Permalink
Fix #2303
Browse files Browse the repository at this point in the history
  • Loading branch information
cowtowncoder committed May 8, 2019
1 parent 4b630c6 commit f36222e
Show file tree
Hide file tree
Showing 11 changed files with 54 additions and 14 deletions.
5 changes: 5 additions & 0 deletions release-notes/CREDITS-2.x
Original file line number Diff line number Diff line change
Expand Up @@ -837,3 +837,8 @@ Joffrey Bion (joffrey-bion@github)
Christoph ([email protected])
* Contributed #2299: Fix for using jackson-databind in an OSGi environment under Android
(2.9.9)

Cyril Martin ([email protected])
* Reported #2303: Deserialize null, when java type is "TypeRef of TypeRef of T",
does not provide "Type(Type(null))"
(2.9.9)
2 changes: 2 additions & 0 deletions release-notes/VERSION-2.x
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@ Project: jackson-databind
(reported by Joffrey B)
#2299: Fix for using jackson-databind in an OSGi environment under Android
(contributed by Christoph F)
#2303: Deserialize null, when java type is "TypeRef of TypeRef of T", does not provide "Type(Type(null))"
(reported by Cyril M)
- Prevent String coercion of `null` in `WritableObjectId` when calling `JsonGenerator.writeObjectId()`,
mostly relevant for formats like YAML that have native Object Ids

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,9 @@ public SettableBeanProperty withValueDeserializer(JsonDeserializer<?> deser) {
if (_valueDeserializer == deser) {
return this;
}
return new CreatorProperty(this, deser, _nullProvider);
// 07-May-2019, tatu: As per [databind#2303], must keep VD/NVP in-sync if they were
NullValueProvider nvp = (_valueDeserializer == _nullProvider) ? deser : _nullProvider;
return new CreatorProperty(this, deser, nvp);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,9 @@ public SettableBeanProperty withValueDeserializer(JsonDeserializer<?> deser) {
if (_valueDeserializer == deser) {
return this;
}
return new FieldProperty(this, deser, _nullProvider);
// 07-May-2019, tatu: As per [databind#2303], must keep VD/NVP in-sync if they were
NullValueProvider nvp = (_valueDeserializer == _nullProvider) ? deser : _nullProvider;
return new FieldProperty(this, deser, nvp);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,9 @@ public SettableBeanProperty withValueDeserializer(JsonDeserializer<?> deser) {
if (_valueDeserializer == deser) {
return this;
}
return new MethodProperty(this, deser, _nullProvider);
// 07-May-2019, tatu: As per [databind#2303], must keep VD/NVP in-sync if they were
NullValueProvider nvp = (_valueDeserializer == _nullProvider) ? deser : _nullProvider;
return new MethodProperty(this, deser, nvp);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,9 @@ public SettableBeanProperty withValueDeserializer(JsonDeserializer<?> deser) {
if (_valueDeserializer == deser) {
return this;
}
return new ObjectIdReferenceProperty(this, deser, _nullProvider);
// 07-May-2019, tatu: As per [databind#2303], must keep VD/NVP in-sync if they were
NullValueProvider nvp = (_valueDeserializer == _nullProvider) ? deser : _nullProvider;
return new ObjectIdReferenceProperty(this, deser, nvp);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,9 @@ public SettableBeanProperty withValueDeserializer(JsonDeserializer<?> deser) {
if (_valueDeserializer == deser) {
return this;
}
return new ObjectIdValueProperty(this, deser, _nullProvider);
// 07-May-2019, tatu: As per [databind#2303], must keep VD/NVP in-sync if they were
NullValueProvider nvp = (_valueDeserializer == _nullProvider) ? deser : _nullProvider;
return new ObjectIdValueProperty(this, deser, nvp);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,9 @@ public SettableBeanProperty withValueDeserializer(JsonDeserializer<?> deser) {
if (_valueDeserializer == deser) {
return this;
}
return new SetterlessProperty(this, deser, _nullProvider);
// 07-May-2019, tatu: As per [databind#2303], must keep VD/NVP in-sync if they were
NullValueProvider nvp = (_valueDeserializer == _nullProvider) ? deser : _nullProvider;
return new SetterlessProperty(this, deser, nvp);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,9 +37,10 @@ public AtomicReferenceDeserializer withResolved(TypeDeserializer typeDeser, Json
return new AtomicReferenceDeserializer(_fullType, _valueInstantiator,
typeDeser, valueDeser);
}

@Override
public AtomicReference<Object> getNullValue(DeserializationContext ctxt) {
return new AtomicReference<Object>();
public AtomicReference<Object> getNullValue(DeserializationContext ctxt) throws JsonMappingException {
return new AtomicReference<Object>(_valueDeserializer.getNullValue(ctxt));
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -118,10 +118,10 @@ protected abstract ReferenceTypeDeserializer<T> withResolved(TypeDeserializer ty
JsonDeserializer<?> valueDeser);

@Override
public abstract T getNullValue(DeserializationContext ctxt);
public abstract T getNullValue(DeserializationContext ctxt) throws JsonMappingException;

@Override
public Object getEmptyValue(DeserializationContext ctxt) {
public Object getEmptyValue(DeserializationContext ctxt) throws JsonMappingException {
return getNullValue(ctxt);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,11 @@

import com.fasterxml.jackson.annotation.*;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.databind.ObjectReader;
import com.fasterxml.jackson.databind.annotation.JsonDeserialize;
import com.fasterxml.jackson.databind.annotation.JsonSerialize;

public class JDKAtomicTypesTest
public class JDKAtomicTypesDeserTest
extends com.fasterxml.jackson.databind.BaseMapTest
{
@JsonTypeInfo(use = JsonTypeInfo.Id.NAME)
Expand Down Expand Up @@ -93,6 +94,11 @@ static class Issue1256Bean {
public AtomicReference<Object> b = new AtomicReference<Object>();
}

// [databind#2303]
static class MyBean2303 {
public AtomicReference<AtomicReference<Integer>> refRef;
}

/*
/**********************************************************
/* Test methods
Expand Down Expand Up @@ -271,11 +277,25 @@ public void testEmpty1256() throws Exception
@SuppressWarnings("unchecked")
public void testNullValueHandling() throws Exception
{
ObjectMapper mapper = new ObjectMapper();
AtomicReference<Double> inputData = new AtomicReference<Double>();
String json = mapper.writeValueAsString(inputData);
AtomicReference<Double> readData = (AtomicReference<Double>) mapper.readValue(json, AtomicReference.class);
String json = MAPPER.writeValueAsString(inputData);
AtomicReference<Double> readData = (AtomicReference<Double>) MAPPER.readValue(json, AtomicReference.class);
assertNotNull(readData);
assertNull(readData.get());
}

// [databind#2303]
public void testNullWithinNested() throws Exception
{
final ObjectReader r = MAPPER.readerFor(MyBean2303.class);
MyBean2303 intRef = r.readValue(" {\"refRef\": 2 } ");
assertNotNull(intRef.refRef);
assertNotNull(intRef.refRef.get());
assertEquals(intRef.refRef.get().get(), new Integer(2));

MyBean2303 nullRef = r.readValue(" {\"refRef\": null } ");
assertNotNull(nullRef.refRef);
assertNotNull(nullRef.refRef.get());
assertNull(nullRef.refRef.get().get());
}
}

0 comments on commit f36222e

Please sign in to comment.