|
10 | 10 |
|
11 | 11 | import com.fasterxml.jackson.databind.*;
|
12 | 12 | import com.fasterxml.jackson.databind.cfg.MapperConfig;
|
| 13 | +import com.fasterxml.jackson.databind.deser.std.StringDeserializer; |
| 14 | +import com.fasterxml.jackson.databind.deser.std.UntypedObjectDeserializer; |
13 | 15 | import com.fasterxml.jackson.databind.jsontype.NamedType;
|
14 | 16 | import com.fasterxml.jackson.databind.jsontype.TypeResolverBuilder;
|
| 17 | +import com.fasterxml.jackson.databind.ser.std.StringSerializer; |
| 18 | +import com.fasterxml.jackson.databind.ser.std.ToStringSerializer; |
15 | 19 |
|
16 | 20 | // started with [databind#1025] in mind
|
17 | 21 | @SuppressWarnings("serial")
|
@@ -45,12 +49,38 @@ public JsonInclude.Value findPropertyInclusion(Annotated a) {
|
45 | 49 | }
|
46 | 50 | }
|
47 | 51 |
|
| 52 | + static class IntrospectorWithHandlers extends AnnotationIntrospector { |
| 53 | + final JsonDeserializer<?> _deserializer; |
| 54 | + final JsonSerializer<?> _serializer; |
| 55 | + |
| 56 | + public IntrospectorWithHandlers(JsonDeserializer<?> deser, |
| 57 | + JsonSerializer<?> ser) { |
| 58 | + _deserializer = deser; |
| 59 | + _serializer = ser; |
| 60 | + } |
| 61 | + |
| 62 | + @Override |
| 63 | + public Version version() { |
| 64 | + return Version.unknownVersion(); |
| 65 | + } |
| 66 | + |
| 67 | + @Override |
| 68 | + public Object findDeserializer(Annotated am) { |
| 69 | + return _deserializer; |
| 70 | + } |
| 71 | + |
| 72 | + @Override |
| 73 | + public Object findSerializer(Annotated am) { |
| 74 | + return _serializer; |
| 75 | + } |
| 76 | + } |
| 77 | + |
48 | 78 | static class IntrospectorWithMap extends AnnotationIntrospector
|
49 | 79 | {
|
50 | 80 | private final Map<String, Object> values = new HashMap<>();
|
51 | 81 |
|
52 | 82 | private Version version = Version.unknownVersion();
|
53 |
| - |
| 83 | + |
54 | 84 | public IntrospectorWithMap add(String key, Object value) {
|
55 | 85 | values.put(key, value);
|
56 | 86 | return this;
|
@@ -223,7 +253,7 @@ public void testAnnotationBundle() throws Exception
|
223 | 253 | assertFalse(new AnnotationIntrospectorPair(NO_ANNOTATIONS, NO_ANNOTATIONS)
|
224 | 254 | .isAnnotationBundle(null));
|
225 | 255 | }
|
226 |
| - |
| 256 | + |
227 | 257 | /*
|
228 | 258 | /**********************************************************
|
229 | 259 | /* Test methods, general class annotations
|
@@ -305,6 +335,48 @@ public void testFindClassDescription() throws Exception
|
305 | 335 |
|
306 | 336 | // // // 3 deprecated methods, skip
|
307 | 337 |
|
| 338 | + /* |
| 339 | + /********************************************************** |
| 340 | + /* Test methods, ser/deser |
| 341 | + /********************************************************** |
| 342 | + */ |
| 343 | + |
| 344 | + public void testFindSerializer() throws Exception |
| 345 | + { |
| 346 | + final JsonSerializer<?> serString = new StringSerializer(); |
| 347 | + final JsonSerializer<?> serToString = ToStringSerializer.instance; |
| 348 | + |
| 349 | + AnnotationIntrospector intr1 = new IntrospectorWithHandlers(null, serString); |
| 350 | + AnnotationIntrospector intr2 = new IntrospectorWithHandlers(null, serToString); |
| 351 | + AnnotationIntrospector nop = AnnotationIntrospector.nopInstance(); |
| 352 | + |
| 353 | + assertSame(serString, |
| 354 | + new AnnotationIntrospectorPair(intr1, intr2).findSerializer(null)); |
| 355 | + assertSame(serToString, |
| 356 | + new AnnotationIntrospectorPair(intr2, intr1).findSerializer(null)); |
| 357 | + // also: no-op instance should not block real one, regardless |
| 358 | + assertSame(serString, |
| 359 | + new AnnotationIntrospectorPair(nop, intr1).findSerializer(null)); |
| 360 | + } |
| 361 | + |
| 362 | + public void testFindDeserializer() throws Exception |
| 363 | + { |
| 364 | + final JsonDeserializer<?> deserString = StringDeserializer.instance; |
| 365 | + final JsonDeserializer<?> deserObject = UntypedObjectDeserializer.Vanilla.std; |
| 366 | + |
| 367 | + AnnotationIntrospector intr1 = new IntrospectorWithHandlers(deserString, null); |
| 368 | + AnnotationIntrospector intr2 = new IntrospectorWithHandlers(deserObject, null); |
| 369 | + AnnotationIntrospector nop = AnnotationIntrospector.nopInstance(); |
| 370 | + |
| 371 | + assertSame(deserString, |
| 372 | + new AnnotationIntrospectorPair(intr1, intr2).findDeserializer(null)); |
| 373 | + assertSame(deserObject, |
| 374 | + new AnnotationIntrospectorPair(intr2, intr1).findDeserializer(null)); |
| 375 | + // also: no-op instance should not block real one, regardless |
| 376 | + assertSame(deserString, |
| 377 | + new AnnotationIntrospectorPair(nop, intr1).findDeserializer(null)); |
| 378 | + } |
| 379 | + |
308 | 380 | /*
|
309 | 381 | /******************************************************
|
310 | 382 | /* Property auto-detection
|
|
0 commit comments