Skip to content

Commit f609683

Browse files
committed
Fixed #1388
1 parent 00fd5ee commit f609683

File tree

3 files changed

+27
-16
lines changed

3 files changed

+27
-16
lines changed

release-notes/VERSION

+3
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,9 @@ Project: jackson-databind
66

77
2.8.6 (not yet released)
88

9+
#1388: `@JsonIdentityInfo`: id has to be the first key in deserialization when
10+
deserializing with `@JsonCreator`
11+
(reported by moodysalem@github)
912
#1425: `JsonNode.binaryValue()` ignores illegal character if it's the last one
1013
(reported by binoternary@github)
1114
#1453: `UntypedObjectDeserializer` does not retain `float` type (over `double`)

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

+7-4
Original file line numberDiff line numberDiff line change
@@ -107,9 +107,8 @@ public final boolean hasParameter(SettableBeanProperty prop)
107107
{
108108
if (_paramsSeenBig == null) {
109109
return ((_paramsSeen >> prop.getCreatorIndex()) & 1) == 1;
110-
} else {
111-
return _paramsSeenBig.get(prop.getCreatorIndex());
112110
}
111+
return _paramsSeenBig.get(prop.getCreatorIndex());
113112
}
114113

115114
/**
@@ -250,6 +249,9 @@ public Object handleIdValue(final DeserializationContext ctxt, Object bean) thro
250249
public boolean isComplete() { return _paramsNeeded <= 0; }
251250

252251
/**
252+
* Method called to buffer value for given property, as well as check whether
253+
* we now have values for all (creator) properties that we expect to get values for.
254+
*
253255
* @return True if we have received all creator parameters
254256
*
255257
* @since 2.6
@@ -265,14 +267,15 @@ public boolean assignParameter(SettableBeanProperty prop, Object value)
265267
if (old != newValue) {
266268
_paramsSeen = newValue;
267269
if (--_paramsNeeded <= 0) {
268-
return true;
270+
// 29-Nov-2016, tatu: But! May still require Object Id value
271+
return (_objectIdReader == null) || (_idValue != null);
269272
}
270273
}
271274
} else {
272275
if (!_paramsSeenBig.get(ix)) {
273276
_paramsSeenBig.set(ix);
274277
if (--_paramsNeeded <= 0) {
275-
return true;
278+
// 29-Nov-2016, tatu: But! May still require Object Id value
276279
}
277280
}
278281
}

src/test/java/com/fasterxml/jackson/failing/JsonIdentiyInfo1388Test.java renamed to src/test/java/com/fasterxml/jackson/databind/objectid/ObjectIdReordering1388Test.java

+17-12
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
1-
package com.fasterxml.jackson.failing;
1+
package com.fasterxml.jackson.databind.objectid;
22

33
import java.util.*;
44

55
import com.fasterxml.jackson.annotation.*;
66
import com.fasterxml.jackson.core.type.TypeReference;
77
import com.fasterxml.jackson.databind.*;
88

9-
public class JsonIdentiyInfo1388Test extends BaseMapTest
9+
public class ObjectIdReordering1388Test extends BaseMapTest
1010
{
1111
@JsonIdentityInfo(generator = ObjectIdGenerators.IntSequenceGenerator.class)
1212
public static class NamedThing {
@@ -50,28 +50,33 @@ public void testDeserializationFinalClassJSOG() throws Exception
5050

5151
final TypeReference<?> namedThingListType = new TypeReference<List<NamedThing>>() { };
5252

53-
final String jsog = mapper.writeValueAsString(Arrays.asList(thing, thing, thing));
5453
{
54+
final String jsog = mapper.writeValueAsString(Arrays.asList(thing, thing, thing));
5555
final List<NamedThing> list = mapper.readValue(jsog, namedThingListType);
5656
_assertAllSame(list);
57+
// this is the jsog representation of the list of 3 of the same item
58+
assertTrue(jsog.equals("[{\"@id\":1,\"id\":\"a59aa02c-fe3c-43f8-9b5a-5fe01878a818\",\"name\":\"Hello\"},1,1]"));
5759
}
5860

59-
// this is the jsog representation of the list of 3 of the same item
60-
assertTrue(jsog.equals("[{\"@id\":1,\"id\":\"a59aa02c-fe3c-43f8-9b5a-5fe01878a818\",\"name\":\"Hello\"},1,1]"));
61-
6261
// now move it around it have forward references
63-
final String forwardReferences = "[1,1,{\"@id\":1,\"id\":\"a59aa02c-fe3c-43f8-9b5a-5fe01878a818\",\"name\":\"Hello\"}]";
6462
// this works
6563
{
66-
final List<NamedThing> forward = mapper.readValue(forwardReferences, namedThingListType);
64+
final String json = "[1,1,{\"@id\":1,\"id\":\"a59aa02c-fe3c-43f8-9b5a-5fe01878a818\",\"name\":\"Hello\"}]";
65+
final List<NamedThing> forward = mapper.readValue(json, namedThingListType);
66+
_assertAllSame(forward);
67+
}
68+
69+
// next, move @id to between properties
70+
{
71+
final String json = aposToQuotes("[{'id':'a59aa02c-fe3c-43f8-9b5a-5fe01878a818','@id':1,'name':'Hello'}, 1, 1]");
72+
final List<NamedThing> forward = mapper.readValue(json, namedThingListType);
6773
_assertAllSame(forward);
6874
}
6975

70-
// now move the @id to be not the first key in the object
71-
final String notFirstKey = "[1,1,{\"id\":\"a59aa02c-fe3c-43f8-9b5a-5fe01878a818\",\"name\":\"Hello\",\"@id\":1}]";
72-
// this fails
76+
// and last, move @id to be not the first key in the object
7377
{
74-
final List<NamedThing> forward = mapper.readValue(notFirstKey, namedThingListType);
78+
final String json = aposToQuotes("[{'id':'a59aa02c-fe3c-43f8-9b5a-5fe01878a818','name':'Hello','@id':1}, 1, 1]");
79+
final List<NamedThing> forward = mapper.readValue(json, namedThingListType);
7580
_assertAllSame(forward);
7681
}
7782
}

0 commit comments

Comments
 (0)