Skip to content

Commit 87bd61a

Browse files
author
Aritz Bastida
committed
Add test case for issue FasterXML#3160 (JsonStreamContext "currentValue" wrongly references to @JsonTypeInfo annotated object)
1 parent 391c91a commit 87bd61a

File tree

1 file changed

+38
-13
lines changed

1 file changed

+38
-13
lines changed

src/test/java/com/fasterxml/jackson/databind/ser/TestCustomSerializers.java

Lines changed: 38 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,8 @@
88

99
import org.w3c.dom.Element;
1010

11-
import com.fasterxml.jackson.annotation.JsonFilter;
12-
import com.fasterxml.jackson.annotation.JsonFormat;
13-
import com.fasterxml.jackson.annotation.JsonPropertyOrder;
11+
import com.fasterxml.jackson.annotation.*;
12+
import com.fasterxml.jackson.annotation.JsonTypeInfo.As;
1413
import com.fasterxml.jackson.core.*;
1514
import com.fasterxml.jackson.core.io.CharacterEscapes;
1615
import com.fasterxml.jackson.databind.*;
@@ -166,24 +165,43 @@ public void serializeAsField(Object pojo, JsonGenerator jgen, SerializerProvider
166165
}
167166

168167
@JsonFilter("myFilter")
169-
@JsonPropertyOrder({ "id", "set" })
168+
@JsonPropertyOrder({ "id", "strategy", "set" })
170169
public static class Item2475 {
170+
171171
private Collection<String> set;
172-
private String id;
172+
private Strategy strategy;
173+
private String id;
173174

174175
public Item2475(Collection<String> set, String id) {
175176
this.set = set;
177+
this.strategy = new Foo(42);
176178
this.id = id;
177179
}
178180

179181
public Collection<String> getSet() {
180182
return set;
181183
}
184+
185+
public Strategy getStrategy() {
186+
return strategy;
187+
}
182188

183189
public String getId() {
184190
return id;
185191
}
186192
}
193+
194+
@JsonTypeInfo(use = JsonTypeInfo.Id.MINIMAL_CLASS, include = As.PROPERTY, property = "@class")
195+
interface Strategy { }
196+
197+
static class Foo implements Strategy {
198+
public int foo;
199+
200+
@JsonCreator
201+
Foo(@JsonProperty("foo") int foo) {
202+
this.foo = foo;
203+
}
204+
}
187205

188206
/*
189207
/**********************************************************
@@ -292,17 +310,24 @@ public void testWithCustomElements() throws Exception
292310
}
293311

294312
// [databind#2475]
295-
public void testIssue2475() throws Exception {
313+
public void testIssue2475Filter() throws Exception {
296314
SimpleFilterProvider provider = new SimpleFilterProvider().addFilter("myFilter", new MyFilter2475());
297315
ObjectWriter writer = MAPPER.writer(provider);
316+
317+
writer.writeValueAsString(new Item2475(new ArrayList<String>(), "ID-1"));
318+
}
298319

299-
// contents don't really matter that much as verification within filter but... let's
300-
// check anyway
301-
assertEquals(aposToQuotes("{'id':'ID-1','set':[]}"),
302-
writer.writeValueAsString(new Item2475(new ArrayList<String>(), "ID-1")));
320+
// [databind#2475]
321+
public void testIssue2475Contents() throws Exception {
322+
SimpleFilterProvider provider = new SimpleFilterProvider().addFilter("myFilter", new SimpleBeanPropertyFilter() {});
323+
ObjectWriter writer = MAPPER.writer(provider);
324+
325+
assertEquals(aposToQuotes("{'id':'ID-1','strategy':{'foo':42},'set':[]}"),
326+
writer.writeValueAsString(new Item2475(new ArrayList<String>(), "ID-1")));
303327

304-
assertEquals(aposToQuotes("{'id':'ID-2','set':[]}"),
305-
writer.writeValueAsString(new Item2475(new HashSet<String>(), "ID-2")));
306-
}
328+
assertEquals(aposToQuotes("{'id':'ID-2','strategy':{'foo':42},'set':[]}"),
329+
writer.writeValueAsString(new Item2475(new HashSet<String>(), "ID-2")));
330+
}
331+
307332

308333
}

0 commit comments

Comments
 (0)