Skip to content

Commit ed98f34

Browse files
committed
Merge pull request #881 from dharaburda/creators-identity-patch
BeanDeserializerBase (2.6.0 regression): only update creatorProps with CreatorPropertys
2 parents 5d2b253 + 4d4ddae commit ed98f34

File tree

2 files changed

+56
-1
lines changed

2 files changed

+56
-1
lines changed

src/main/java/com/fasterxml/jackson/databind/deser/BeanDeserializerBase.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -481,7 +481,7 @@ public void resolve(DeserializationContext ctxt)
481481
// 18-May-2015, tatu: _Should_ start with consistent set. But can we really
482482
// fully count on this? May need to revisit in future; seems to hold for now.
483483
for (int i = 0, len = creatorProps.length; i < len; ++i) {
484-
if (creatorProps[i] == origProp) {
484+
if (creatorProps[i] == origProp && prop instanceof CreatorProperty) {
485485
creatorProps[i] = prop;
486486
break;
487487
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
package com.fasterxml.jackson.databind.creators;
2+
3+
import java.io.IOException;
4+
5+
import com.fasterxml.jackson.annotation.JsonCreator;
6+
import com.fasterxml.jackson.annotation.JsonIdentityInfo;
7+
import com.fasterxml.jackson.annotation.JsonProperty;
8+
import com.fasterxml.jackson.annotation.ObjectIdGenerators;
9+
import com.fasterxml.jackson.databind.BaseMapTest;
10+
import com.fasterxml.jackson.databind.ObjectMapper;
11+
12+
/**
13+
* @author dharaburda
14+
*/
15+
public class TestCreatorsWithIdentity extends BaseMapTest {
16+
17+
@JsonIdentityInfo(generator=ObjectIdGenerators.PropertyGenerator.class, property="id", scope=Parent.class)
18+
public static class Parent {
19+
@JsonProperty("id")
20+
String id;
21+
22+
@JsonProperty
23+
String parentProp;
24+
25+
@JsonCreator
26+
public Parent(@JsonProperty("parentProp") String parentProp) {
27+
this.parentProp = parentProp;
28+
}
29+
}
30+
31+
32+
public static class Child {
33+
@JsonProperty
34+
Parent parent;
35+
36+
@JsonProperty
37+
String childProp;
38+
39+
@JsonCreator
40+
public Child(@JsonProperty("parent") Parent parent, @JsonProperty("childProp") String childProp) {
41+
this.parent = parent;
42+
this.childProp = childProp;
43+
}
44+
}
45+
46+
private static final ObjectMapper JSON_MAPPER = new ObjectMapper();
47+
48+
public void test() throws IOException {
49+
String parentStr = "{\"id\" : \"1\", \"parentProp\" : \"parent\"}";
50+
String childStr = "{\"childProp\" : \"child\", \"parent\" : " + parentStr + "}";
51+
Parent parent = JSON_MAPPER.readValue(parentStr, Parent.class);
52+
Child child = JSON_MAPPER.readValue(childStr, Child.class);
53+
}
54+
55+
}

0 commit comments

Comments
 (0)