Skip to content

Commit a290f09

Browse files
committed
Fix #1150
1 parent ad53425 commit a290f09

File tree

4 files changed

+39
-6
lines changed

4 files changed

+39
-6
lines changed

release-notes/CREDITS

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -426,3 +426,7 @@ Timur Shakurov (saladinkzn@github)
426426
Jiri Mikulasek (pirkogdc@github)
427427
* Reported #1124: JsonAnyGetter ignores JsonSerialize(contentUsing=...)
428428
(2.7.2)
429+
430+
Xavi Torrens (xavitorrens@github)
431+
* Reported #1150: Problem with Object id handling, explicit `null` token
432+
(2.7.3)

release-notes/VERSION

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,12 @@ Project: jackson-databind
44
=== Releases ===
55
------------------------------------------------------------------------
66

7-
2.7.2 (not released yet)
7+
2.7.3 (not yet released)
8+
9+
#1150: Problem with Object id handling, explicit `null` token
10+
(reported by Xavi T)
11+
12+
2.7.2 (26-Feb-2016)
813

914
#1124: JsonAnyGetter ignores JsonSerialize(contentUsing=...)
1015
(reported by Jiri M)

src/main/java/com/fasterxml/jackson/databind/deser/impl/ObjectIdValueProperty.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
import java.lang.annotation.Annotation;
55

66
import com.fasterxml.jackson.core.JsonParser;
7+
import com.fasterxml.jackson.core.JsonToken;
78
import com.fasterxml.jackson.databind.*;
89
import com.fasterxml.jackson.databind.deser.*;
910
import com.fasterxml.jackson.databind.introspect.AnnotatedMember;
@@ -75,17 +76,16 @@ public void deserializeAndSet(JsonParser p, DeserializationContext ctxt,
7576
public Object deserializeSetAndReturn(JsonParser p,
7677
DeserializationContext ctxt, Object instance) throws IOException
7778
{
78-
// note: no null checks (unlike usually); deserializer should fail if one found
79-
Object id = _valueDeserializer.deserialize(p, ctxt);
80-
8179
/* 02-Apr-2015, tatu: Actually, as per [databind#742], let it be;
8280
* missing or null id is needed for some cases, such as cases where id
8381
* will be generated externally, at a later point, and is not available
8482
* quite yet. Typical use case is with DB inserts.
8583
*/
86-
if (id == null) {
84+
// note: no null checks (unlike usually); deserializer should fail if one found
85+
if (p.hasToken(JsonToken.VALUE_NULL)) {
8786
return null;
8887
}
88+
Object id = _valueDeserializer.deserialize(p, ctxt);
8989
ReadableObjectId roid = ctxt.findObjectId(id, _objectIdReader.generator, _objectIdReader.resolver);
9090
roid.bindItem(instance);
9191
// also: may need to set a property value as well

src/test/java/com/fasterxml/jackson/databind/objectid/TestObjectIdSerialization.java

Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -163,6 +163,21 @@ static class Broken
163163
@JsonIdentityInfo(generator=ObjectIdGenerators.IntSequenceGenerator.class, property="@id")
164164
public static class EmptyObject { }
165165

166+
//for [databind#1150]
167+
@JsonIdentityInfo(generator=ObjectIdGenerators.PropertyGenerator.class, property="id")
168+
static class IdentifiableStringId
169+
{
170+
public String id;
171+
public int value;
172+
173+
public Identifiable next;
174+
175+
public IdentifiableStringId() { this(0); }
176+
public IdentifiableStringId(int v) {
177+
value = v;
178+
}
179+
}
180+
166181
/*
167182
/*****************************************************
168183
/* Unit tests, external id serialization
@@ -294,7 +309,16 @@ public void testAlwaysIdForTree() throws Exception
294309
json);
295310

296311
}
297-
312+
313+
//for [databind#1150]
314+
public void testNullStringPropertyId() throws Exception
315+
{
316+
IdentifiableStringId value = MAPPER.readValue
317+
(aposToQuotes("{'value':3, 'next':null, 'id':null}"), IdentifiableStringId.class);
318+
assertNotNull(value);
319+
assertEquals(3, value.value);
320+
}
321+
298322
/*
299323
/*****************************************************
300324
/* Unit tests, error handling

0 commit comments

Comments
 (0)