Skip to content

Commit 04cb1a2

Browse files
committed
Fixed #1367
1 parent 16d7725 commit 04cb1a2

File tree

4 files changed

+60
-4
lines changed

4 files changed

+60
-4
lines changed

release-notes/CREDITS

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -489,6 +489,10 @@ Josh Caplan (jecaplan@github)
489489
Frédéric Camblor (fcamblor@github)
490490
* Reported #1451: Type parameter not passed by `ObjectWriter` if serializer pre-fetch disabled
491491

492+
Diego de Estrada (diegode@github)
493+
* Contributed fix for #1367: No Object Id found for an instance when using `@ConstructorProperties`
494+
(2.7.9)
495+
492496
Kevin Hogeland (khogeland@github)
493497
* Reported #1501: `ArrayIndexOutOfBoundsException` on non-static inner class constructor
494498
(2.7.9)

release-notes/VERSION

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@ Project: jackson-databind
66

77
2.7.9 (not yet released)
88

9+
#1367: No Object Id found for an instance when using `@ConstructorProperties`
10+
(reported by kajo-bellabeat@github; fix by diegode@github)
911
#1392: Custom UnmodifiableSetMixin Fails in Jackson 2.7+ but works in Jackson 2.6
1012
(reported by Rob W)
1113
#1411: MapSerializer._orderEntries should check for null keys

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

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -373,6 +373,10 @@ protected Object _deserializeUsingPropertyBased(final JsonParser p, final Deseri
373373
for (; t == JsonToken.FIELD_NAME; t = p.nextToken()) {
374374
String propName = p.getCurrentName();
375375
p.nextToken(); // to point to value
376+
// Object Id property?
377+
if (buffer.readIdProperty(propName)) {
378+
continue;
379+
}
376380
// creator property?
377381
SettableBeanProperty creatorProp = creator.findCreatorProperty(propName);
378382
if (creatorProp != null) {
@@ -405,10 +409,6 @@ protected Object _deserializeUsingPropertyBased(final JsonParser p, final Deseri
405409
}
406410
continue;
407411
}
408-
// Object Id property?
409-
if (buffer.readIdProperty(propName)) {
410-
continue;
411-
}
412412
// regular property? needs buffering
413413
SettableBeanProperty prop = _beanProperties.find(propName);
414414
if (prop != null) {
Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
package com.fasterxml.jackson.databind.creators;
2+
3+
import java.beans.ConstructorProperties;
4+
5+
import com.fasterxml.jackson.annotation.JsonIdentityInfo;
6+
import com.fasterxml.jackson.annotation.ObjectIdGenerators;
7+
import com.fasterxml.jackson.databind.*;
8+
9+
// for [databind#1367]
10+
public class CreatorWithObjectIdTest
11+
extends BaseMapTest
12+
{
13+
@JsonIdentityInfo(generator = ObjectIdGenerators.PropertyGenerator.class, property = "id")
14+
// resolver = SimpleObjectIdResolver.class)
15+
public static class A {
16+
String id;
17+
String name;
18+
19+
public A() { }
20+
21+
@ConstructorProperties({"id", "name"})
22+
public A(String id, String name) {
23+
this.id = id;
24+
this.name = name;
25+
}
26+
27+
public String getId() {
28+
return id;
29+
}
30+
public void setId(String id) {
31+
this.id = id;
32+
}
33+
public String getName() {
34+
return name;
35+
}
36+
public void setName(String name) {
37+
this.name = name;
38+
}
39+
}
40+
41+
public void testObjectIdWithCreator() throws Exception
42+
{
43+
A a = new A("123", "A");
44+
45+
ObjectMapper om = new ObjectMapper();
46+
String json = om.writeValueAsString(a);
47+
A deser = om.readValue(json, A.class);
48+
assertEquals(a.name, deser.name);
49+
}
50+
}

0 commit comments

Comments
 (0)