Skip to content

Commit d455965

Browse files
committed
Fixed #1581
1 parent d71a237 commit d455965

File tree

2 files changed

+79
-5
lines changed

2 files changed

+79
-5
lines changed

src/main/java/com/fasterxml/jackson/databind/introspect/AnnotationIntrospectorPair.java

+5-3
Original file line numberDiff line numberDiff line change
@@ -781,10 +781,12 @@ public boolean hasAnySetterAnnotation(AnnotatedMethod am) {
781781
}
782782

783783
protected boolean _isExplicitClassOrOb(Object maybeCls, Class<?> implicit) {
784+
if ((maybeCls == null) || (maybeCls == implicit)) {
785+
return false;
786+
}
784787
if (maybeCls instanceof Class<?>) {
785-
Class<?> cls = (Class<?>) maybeCls;
786-
return (cls != implicit) && !ClassUtil.isBogusClass(cls);
788+
return !ClassUtil.isBogusClass((Class<?>) maybeCls);
787789
}
788-
return false;
790+
return true;
789791
}
790792
}

src/test/java/com/fasterxml/jackson/databind/introspect/IntrospectorPairTest.java

+74-2
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,12 @@
1010

1111
import com.fasterxml.jackson.databind.*;
1212
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;
1315
import com.fasterxml.jackson.databind.jsontype.NamedType;
1416
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;
1519

1620
// started with [databind#1025] in mind
1721
@SuppressWarnings("serial")
@@ -45,12 +49,38 @@ public JsonInclude.Value findPropertyInclusion(Annotated a) {
4549
}
4650
}
4751

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+
4878
static class IntrospectorWithMap extends AnnotationIntrospector
4979
{
5080
private final Map<String, Object> values = new HashMap<>();
5181

5282
private Version version = Version.unknownVersion();
53-
83+
5484
public IntrospectorWithMap add(String key, Object value) {
5585
values.put(key, value);
5686
return this;
@@ -223,7 +253,7 @@ public void testAnnotationBundle() throws Exception
223253
assertFalse(new AnnotationIntrospectorPair(NO_ANNOTATIONS, NO_ANNOTATIONS)
224254
.isAnnotationBundle(null));
225255
}
226-
256+
227257
/*
228258
/**********************************************************
229259
/* Test methods, general class annotations
@@ -305,6 +335,48 @@ public void testFindClassDescription() throws Exception
305335

306336
// // // 3 deprecated methods, skip
307337

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+
308380
/*
309381
/******************************************************
310382
/* Property auto-detection

0 commit comments

Comments
 (0)