Skip to content

Commit d7a94ed

Browse files
committed
Backport #610 in 2.4(.4), update release notes
1 parent fd4eb1b commit d7a94ed

File tree

4 files changed

+90
-3
lines changed

4 files changed

+90
-3
lines changed

release-notes/CREDITS

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -148,8 +148,12 @@ Steve Sanbeg: (sanbeg@github)
148148

149149
Ian Barfield: (tea-dragon@github)
150150
* Reported #580: delegate deserializers choke on a (single) abstract/polymorphic parameter
151-
(2.4.4)
151+
(2.4.4)
152152

153153
Eugene Lukash
154154
* Reported #592: Wrong `TokenBuffer` delegate deserialization using `@JsonCreator`
155-
(2.4.4)
155+
(2.4.4)
156+
157+
Fernando Otero (zeitos@github)
158+
* Contributed fix for #610: Problem with forward reference in hierarchies
159+
(2.4.4)

release-notes/VERSION

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,8 @@ Project: jackson-databind
2020
#601: ClassCastException for a custom serializer for enum key in `EnumMap`
2121
(reported by Benson M)
2222
#604: `Map` deserializers not being cached, causing performance problems
23+
#610: Fix forward reference in hierarchies
24+
(contributed by zeito@github)
2325
- Minor fix to `EnumSerializer` regarding detection "serialize using index"
2426
- Minor fix to number serializers, to call proper callback for schema generation
2527

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -200,9 +200,10 @@ protected Object _deserializeFromObjectId(JsonParser jp, DeserializationContext
200200
// do we have it resolved?
201201
Object pojo = roid.resolve();
202202
if (pojo == null) { // not yet; should wait...
203-
throw new IllegalStateException("Could not resolve Object Id ["+id+"] -- unresolved forward-reference?");
203+
throw new UnresolvedForwardReference("Could not resolve Object Id ["+id+"] -- unresolved forward-reference?", jp.getCurrentLocation(), roid);
204204
}
205205
return pojo;
206206
}
207207
}
208208

209+
Lines changed: 80 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,80 @@
1+
package com.fasterxml.jackson.databind.deser;
2+
3+
import com.fasterxml.jackson.annotation.JsonIdentityInfo;
4+
import com.fasterxml.jackson.annotation.JsonInclude;
5+
import com.fasterxml.jackson.annotation.JsonProperty;
6+
import com.fasterxml.jackson.annotation.JsonSubTypes;
7+
import com.fasterxml.jackson.annotation.JsonTypeInfo;
8+
import com.fasterxml.jackson.annotation.ObjectIdGenerators;
9+
import com.fasterxml.jackson.core.JsonParseException;
10+
import com.fasterxml.jackson.databind.BaseMapTest;
11+
import com.fasterxml.jackson.databind.DeserializationFeature;
12+
import com.fasterxml.jackson.databind.ObjectMapper;
13+
import com.fasterxml.jackson.databind.SerializationFeature;
14+
15+
import java.io.IOException;
16+
import java.util.ArrayList;
17+
import java.util.List;
18+
19+
/**
20+
* Test for testing forward reference handling
21+
*/
22+
public class TestForwardReference extends BaseMapTest {
23+
24+
private final ObjectMapper MAPPER = new ObjectMapper()
25+
.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false)
26+
.enable(SerializationFeature.INDENT_OUTPUT)
27+
.setSerializationInclusion(JsonInclude.Include.NON_NULL);
28+
29+
/** Tests that we can read a hierarchical structure with forward references*/
30+
public void testForwardRef() throws IOException {
31+
MAPPER.readValue("{" +
32+
" \"@type\" : \"TestForwardReference$ForwardReferenceContainerClass\"," +
33+
" \"frc\" : \"willBeForwardReferenced\"," +
34+
" \"yac\" : {" +
35+
" \"@type\" : \"TestForwardReference$YetAnotherClass\"," +
36+
" \"frc\" : {" +
37+
" \"@type\" : \"One\"," +
38+
" \"id\" : \"willBeForwardReferenced\"" +
39+
" }," +
40+
" \"id\" : \"anId\"" +
41+
" }," +
42+
" \"id\" : \"ForwardReferenceContainerClass1\"" +
43+
"}", ForwardReferenceContainerClass.class);
44+
45+
46+
}
47+
48+
@JsonTypeInfo(use=JsonTypeInfo.Id.NAME, include= JsonTypeInfo.As.PROPERTY)
49+
public static class ForwardReferenceContainerClass
50+
{
51+
public ForwardReferenceClass frc;
52+
public YetAnotherClass yac;
53+
public String id;
54+
}
55+
56+
@JsonTypeInfo(use = JsonTypeInfo.Id.NAME, include = JsonTypeInfo.As.PROPERTY)
57+
@JsonIdentityInfo(generator = ObjectIdGenerators.PropertyGenerator.class, property = "id")
58+
@JsonSubTypes({
59+
@JsonSubTypes.Type(value = ForwardReferenceClassOne.class, name = "One"),
60+
@JsonSubTypes.Type(value = ForwardReferenceClassTwo.class, name = "Two")})
61+
private static abstract class ForwardReferenceClass
62+
{
63+
public String id;
64+
public void setId(String id) {
65+
this.id = id;
66+
}
67+
}
68+
69+
@JsonTypeInfo(use = JsonTypeInfo.Id.NAME, include = JsonTypeInfo.As.PROPERTY)
70+
private static class YetAnotherClass
71+
{
72+
public YetAnotherClass() {}
73+
public ForwardReferenceClass frc;
74+
public String id;
75+
}
76+
77+
public static class ForwardReferenceClassOne extends ForwardReferenceClass { }
78+
79+
public static class ForwardReferenceClassTwo extends ForwardReferenceClass { }
80+
}

0 commit comments

Comments
 (0)