Skip to content

Commit 518b11c

Browse files
committed
Fixed #3060
1 parent fbce266 commit 518b11c

File tree

4 files changed

+59
-9
lines changed

4 files changed

+59
-9
lines changed

release-notes/VERSION-2.x

+1
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ Project: jackson-databind
1919
#3056: MismatchedInputException: Cannot deserialize instance of
2020
`com.fasterxml.jackson.databind.node.ObjectNode` out of VALUE_NULL token
2121
(reported by Stexxen@github)
22+
#3060: Missing override for `hasAsKey()` in `AnnotationIntrospectorPair`
2223

2324
2.12.1 (08-Jan-2021)
2425

src/main/java/com/fasterxml/jackson/databind/AnnotationIntrospector.java

-1
Original file line numberDiff line numberDiff line change
@@ -1021,7 +1021,6 @@ public Boolean hasAsValue(Annotated a) {
10211021
* @since 2.9
10221022
*/
10231023
public Boolean hasAnyGetter(Annotated ann) {
1024-
10251024
// 21-Nov-2016, tatu: Delegate in 2.9; remove redirect from later versions
10261025
if (ann instanceof AnnotatedMethod) {
10271026
if (hasAnyGetterAnnotation((AnnotatedMethod) ann)) {

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

+12-8
Original file line numberDiff line numberDiff line change
@@ -5,15 +5,10 @@
55
import java.util.Collection;
66
import java.util.List;
77

8-
import com.fasterxml.jackson.annotation.JacksonInject;
9-
import com.fasterxml.jackson.annotation.JsonCreator;
10-
import com.fasterxml.jackson.annotation.JsonFormat;
11-
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
12-
import com.fasterxml.jackson.annotation.JsonInclude;
13-
import com.fasterxml.jackson.annotation.JsonIncludeProperties;
14-
import com.fasterxml.jackson.annotation.JsonProperty;
15-
import com.fasterxml.jackson.annotation.JsonSetter;
8+
import com.fasterxml.jackson.annotation.*;
9+
1610
import com.fasterxml.jackson.core.Version;
11+
1712
import com.fasterxml.jackson.databind.*;
1813
import com.fasterxml.jackson.databind.annotation.JsonPOJOBuilder;
1914
import com.fasterxml.jackson.databind.annotation.JsonSerialize;
@@ -611,6 +606,15 @@ public PropertyName findNameForSerialization(Annotated a) {
611606
return n;
612607
}
613608

609+
@Override
610+
public Boolean hasAsKey(MapperConfig<?> config, Annotated a) {
611+
Boolean b = _primary.hasAsKey(config, a);
612+
if (b == null) {
613+
b = _secondary.hasAsKey(config, a);
614+
}
615+
return b;
616+
}
617+
614618
@Override
615619
public Boolean hasAsValue(Annotated a) {
616620
Boolean b = _primary.hasAsValue(a);

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

+46
Original file line numberDiff line numberDiff line change
@@ -422,6 +422,52 @@ public void testHasAsValue() throws Exception
422422
.hasAsValue(null));
423423
}
424424

425+
public void testHasAsKey() throws Exception
426+
{
427+
IntrospectorWithMap intr1 = new IntrospectorWithMap()
428+
.add("hasAsKey", Boolean.TRUE);
429+
IntrospectorWithMap intr2 = new IntrospectorWithMap()
430+
.add("hasAsKey", Boolean.FALSE);
431+
assertNull(new AnnotationIntrospectorPair(NO_ANNOTATIONS, NO_ANNOTATIONS)
432+
.hasAsKey(null, null));
433+
assertEquals(Boolean.TRUE, new AnnotationIntrospectorPair(intr1, NO_ANNOTATIONS)
434+
.hasAsKey(null, null));
435+
assertEquals(Boolean.TRUE, new AnnotationIntrospectorPair(NO_ANNOTATIONS, intr1)
436+
.hasAsKey(null, null));
437+
assertEquals(Boolean.FALSE, new AnnotationIntrospectorPair(intr2, NO_ANNOTATIONS)
438+
.hasAsKey(null, null));
439+
assertEquals(Boolean.FALSE, new AnnotationIntrospectorPair(NO_ANNOTATIONS, intr2)
440+
.hasAsKey(null, null));
441+
442+
assertEquals(Boolean.TRUE, new AnnotationIntrospectorPair(intr1, intr2)
443+
.hasAsKey(null, null));
444+
assertEquals(Boolean.FALSE, new AnnotationIntrospectorPair(intr2, intr1)
445+
.hasAsKey(null, null));
446+
}
447+
448+
public void testHasAnyGetter() throws Exception
449+
{
450+
IntrospectorWithMap intr1 = new IntrospectorWithMap()
451+
.add("hasAnyGetter", Boolean.TRUE);
452+
IntrospectorWithMap intr2 = new IntrospectorWithMap()
453+
.add("hasAnyGetter", Boolean.FALSE);
454+
assertNull(new AnnotationIntrospectorPair(NO_ANNOTATIONS, NO_ANNOTATIONS)
455+
.hasAnyGetter(null));
456+
assertEquals(Boolean.TRUE, new AnnotationIntrospectorPair(intr1, NO_ANNOTATIONS)
457+
.hasAnyGetter(null));
458+
assertEquals(Boolean.TRUE, new AnnotationIntrospectorPair(NO_ANNOTATIONS, intr1)
459+
.hasAnyGetter(null));
460+
assertEquals(Boolean.FALSE, new AnnotationIntrospectorPair(intr2, NO_ANNOTATIONS)
461+
.hasAnyGetter(null));
462+
assertEquals(Boolean.FALSE, new AnnotationIntrospectorPair(NO_ANNOTATIONS, intr2)
463+
.hasAnyGetter(null));
464+
465+
assertEquals(Boolean.TRUE, new AnnotationIntrospectorPair(intr1, intr2)
466+
.hasAnyGetter(null));
467+
assertEquals(Boolean.FALSE, new AnnotationIntrospectorPair(intr2, intr1)
468+
.hasAnyGetter(null));
469+
}
470+
425471
/*
426472
/**********************************************************
427473
/* Test methods, deser

0 commit comments

Comments
 (0)