Skip to content

Commit c6efc45

Browse files
committed
Merge branch '2.12' into 2.13
2 parents 9753e6d + d7de513 commit c6efc45

File tree

4 files changed

+105
-1
lines changed

4 files changed

+105
-1
lines changed

release-notes/CREDITS-2.x

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -905,6 +905,9 @@ Joe Barnett (josephlbarnett@github)
905905
* Reported, contributed fix for #2404: FAIL_ON_MISSING_EXTERNAL_TYPE_ID_PROPERTY setting
906906
ignored when creator properties are buffered
907907
(2.9.10)
908+
* Reported, contributed fix for #3146: Merge findInjectableValues() results in
909+
AnnotationIntrospectorPair
910+
(2.12.4)
908911
909912
Kaki King (kingkk9279@g)
910913
* Reported #2449: Block one more gadget type (cve CVE-2019-14540)

release-notes/VERSION-2.x

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,8 @@ Project: jackson-databind
4141
4242
#3139: Deserialization of "empty" subtype with DEDUCTION failed
4343
(reported by JoeWoo; fix provided by drekbour@github)
44+
#3146: Merge findInjectableValues() results in AnnotationIntrospectorPair
45+
(contributed by Joe B)
4446
4547
2.12.3 (12-Apr-2021)
4648

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

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -300,7 +300,11 @@ public NameTransformer findUnwrappingNameTransformer(AnnotatedMember member) {
300300
@Override
301301
public JacksonInject.Value findInjectableValue(AnnotatedMember m) {
302302
JacksonInject.Value r = _primary.findInjectableValue(m);
303-
return (r == null) ? _secondary.findInjectableValue(m) : r;
303+
if (r == null || r.getUseInput() == null) {
304+
JacksonInject.Value secondary = _secondary.findInjectableValue(m);
305+
r = (r == null || secondary == null) ? secondary : r.withUseInput(secondary.getUseInput());
306+
}
307+
return r;
304308
}
305309

306310
@Override

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

Lines changed: 95 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,15 +3,20 @@
33
import java.lang.annotation.Annotation;
44
import java.util.*;
55

6+
import com.fasterxml.jackson.annotation.JacksonInject;
7+
import com.fasterxml.jackson.annotation.JsonIgnore;
68
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
79
import com.fasterxml.jackson.annotation.JsonInclude;
810

11+
import com.fasterxml.jackson.annotation.JsonProperty;
12+
import com.fasterxml.jackson.annotation.OptBoolean;
913
import com.fasterxml.jackson.core.Version;
1014

1115
import com.fasterxml.jackson.databind.*;
1216
import com.fasterxml.jackson.databind.cfg.MapperConfig;
1317
import com.fasterxml.jackson.databind.deser.std.StringDeserializer;
1418
import com.fasterxml.jackson.databind.deser.std.UntypedObjectDeserializer;
19+
import com.fasterxml.jackson.databind.json.JsonMapper;
1520
import com.fasterxml.jackson.databind.jsontype.NamedType;
1621
import com.fasterxml.jackson.databind.jsontype.TypeResolverBuilder;
1722
import com.fasterxml.jackson.databind.ser.std.StringSerializer;
@@ -601,4 +606,94 @@ public void testInclusionMerging() throws Exception
601606
assertEquals(JsonInclude.Include.NON_EMPTY, v21.getContentInclusion());
602607
assertEquals(JsonInclude.Include.NON_ABSENT, v21.getValueInclusion());
603608
}
609+
610+
/*
611+
/**********************************************************
612+
/* Introspectors and test for [jackson-modules-base#134]/[databind#962]
613+
/**********************************************************
614+
*/
615+
static class TestIntrospector extends NopAnnotationIntrospector {
616+
@Override
617+
public JacksonInject.Value findInjectableValue(AnnotatedMember m) {
618+
if (m.getRawType() == UnreadableBean.class) {
619+
return JacksonInject.Value.forId("jjj");
620+
}
621+
return null;
622+
}
623+
}
624+
625+
static class TestInjector extends InjectableValues {
626+
@Override
627+
public Object findInjectableValue(Object valueId, DeserializationContext ctxt, BeanProperty forProperty, Object beanInstance) {
628+
if (valueId == "jjj") {
629+
UnreadableBean bean = new UnreadableBean();
630+
bean.setValue(1);
631+
return bean;
632+
}
633+
return null;
634+
}
635+
}
636+
637+
enum SimpleEnum { ONE, TWO }
638+
639+
static class UnreadableBean {
640+
public SimpleEnum value;
641+
642+
public void setValue(SimpleEnum value) {
643+
this.value = value;
644+
}
645+
646+
public void setValue(Integer intValue) {
647+
this.value = SimpleEnum.values()[intValue];
648+
}
649+
650+
public SimpleEnum getValue() {
651+
return value;
652+
}
653+
}
654+
655+
static class ReadableInjectedBean {
656+
public ReadableInjectedBean(@JacksonInject(useInput = OptBoolean.FALSE) UnreadableBean injectBean) {
657+
this.injectBean = injectBean;
658+
}
659+
@JsonProperty
660+
private String foo;
661+
@JsonIgnore
662+
private UnreadableBean injectBean;
663+
}
664+
665+
static class UnreadableInjectedBean {
666+
public UnreadableInjectedBean(@JacksonInject UnreadableBean injectBean) {
667+
this.injectBean = injectBean;
668+
}
669+
@JsonProperty
670+
private String foo;
671+
@JsonIgnore
672+
private UnreadableBean injectBean;
673+
}
674+
675+
public void testMergingIntrospectorsForInjection() throws Exception {
676+
AnnotationIntrospector testIntrospector = new TestIntrospector();
677+
ObjectMapper mapper = new JsonMapper();
678+
mapper.setInjectableValues(new TestInjector());
679+
mapper.setAnnotationIntrospectors(
680+
new AnnotationIntrospectorPair(testIntrospector,
681+
mapper.getSerializationConfig().getAnnotationIntrospector()),
682+
new AnnotationIntrospectorPair(testIntrospector,
683+
mapper.getDeserializationConfig().getAnnotationIntrospector())
684+
);
685+
ReadableInjectedBean bean = mapper.readValue("{\"foo\": \"bob\"}", ReadableInjectedBean.class);
686+
assertEquals("bob", bean.foo);
687+
assertEquals(SimpleEnum.TWO, bean.injectBean.value);
688+
689+
boolean successReadingUnreadableInjectedBean;
690+
try {
691+
UnreadableInjectedBean noBean = mapper.readValue("{\"foo\": \"bob\"}", UnreadableInjectedBean.class);
692+
successReadingUnreadableInjectedBean = true;
693+
} catch (JsonMappingException e) {
694+
successReadingUnreadableInjectedBean = false;
695+
assertTrue(e.getMessage().contains("Conflicting setter definitions"));
696+
}
697+
assertFalse(successReadingUnreadableInjectedBean);
698+
}
604699
}

0 commit comments

Comments
 (0)