|
8 | 8 |
|
9 | 9 | import org.w3c.dom.Element;
|
10 | 10 |
|
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; |
14 | 13 | import com.fasterxml.jackson.core.*;
|
15 | 14 | import com.fasterxml.jackson.core.io.CharacterEscapes;
|
16 | 15 | import com.fasterxml.jackson.databind.*;
|
@@ -166,24 +165,43 @@ public void serializeAsField(Object pojo, JsonGenerator jgen, SerializerProvider
|
166 | 165 | }
|
167 | 166 |
|
168 | 167 | @JsonFilter("myFilter")
|
169 |
| - @JsonPropertyOrder({ "id", "set" }) |
| 168 | + @JsonPropertyOrder({ "id", "strategy", "set" }) |
170 | 169 | public static class Item2475 {
|
| 170 | + |
171 | 171 | private Collection<String> set;
|
172 |
| - private String id; |
| 172 | + private Strategy strategy; |
| 173 | + private String id; |
173 | 174 |
|
174 | 175 | public Item2475(Collection<String> set, String id) {
|
175 | 176 | this.set = set;
|
| 177 | + this.strategy = new Foo(42); |
176 | 178 | this.id = id;
|
177 | 179 | }
|
178 | 180 |
|
179 | 181 | public Collection<String> getSet() {
|
180 | 182 | return set;
|
181 | 183 | }
|
| 184 | + |
| 185 | + public Strategy getStrategy() { |
| 186 | + return strategy; |
| 187 | + } |
182 | 188 |
|
183 | 189 | public String getId() {
|
184 | 190 | return id;
|
185 | 191 | }
|
186 | 192 | }
|
| 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 | + } |
187 | 205 |
|
188 | 206 | /*
|
189 | 207 | /**********************************************************
|
@@ -292,17 +310,24 @@ public void testWithCustomElements() throws Exception
|
292 | 310 | }
|
293 | 311 |
|
294 | 312 | // [databind#2475]
|
295 |
| - public void testIssue2475() throws Exception { |
| 313 | + public void testIssue2475Filter() throws Exception { |
296 | 314 | SimpleFilterProvider provider = new SimpleFilterProvider().addFilter("myFilter", new MyFilter2475());
|
297 | 315 | ObjectWriter writer = MAPPER.writer(provider);
|
| 316 | + |
| 317 | + writer.writeValueAsString(new Item2475(new ArrayList<String>(), "ID-1")); |
| 318 | + } |
298 | 319 |
|
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"))); |
303 | 327 |
|
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 | + |
307 | 332 |
|
308 | 333 | }
|
0 commit comments