Skip to content

Commit

Permalink
Merge branch '2.13'
Browse files Browse the repository at this point in the history
  • Loading branch information
cowtowncoder committed May 7, 2021
2 parents 0f96f91 + c6efc45 commit d066e04
Show file tree
Hide file tree
Showing 4 changed files with 109 additions and 1 deletion.
3 changes: 3 additions & 0 deletions release-notes/CREDITS-2.x
Expand Up @@ -905,6 +905,9 @@ Joe Barnett (josephlbarnett@github)
* Reported, contributed fix for #2404: FAIL_ON_MISSING_EXTERNAL_TYPE_ID_PROPERTY setting
ignored when creator properties are buffered
(2.9.10)
* Reported, contributed fix for #3146: Merge findInjectableValues() results in
AnnotationIntrospectorPair
(2.12.4)
Kaki King (kingkk9279@g)
* Reported #2449: Block one more gadget type (cve CVE-2019-14540)
Expand Down
2 changes: 2 additions & 0 deletions release-notes/VERSION-2.x
Expand Up @@ -43,6 +43,8 @@ Project: jackson-databind
#3139: Deserialization of "empty" subtype with DEDUCTION failed
(reported by JoeWoo; fix provided by drekbour@github)
#3146: Merge findInjectableValues() results in AnnotationIntrospectorPair
(contributed by Joe B)
2.12.3 (12-Apr-2021)
Expand Down
Expand Up @@ -284,7 +284,11 @@ public NameTransformer findUnwrappingNameTransformer(MapperConfig<?> config, Ann
@Override
public JacksonInject.Value findInjectableValue(MapperConfig<?> config, AnnotatedMember m) {
JacksonInject.Value r = _primary.findInjectableValue(config, m);
return (r == null) ? _secondary.findInjectableValue(config, m) : r;
if (r == null || r.getUseInput() == null) {
JacksonInject.Value secondary = _secondary.findInjectableValue(config, m);
r = (r == null || secondary == null) ? secondary : r.withUseInput(secondary.getUseInput());
}
return r;
}

@Override
Expand Down
Expand Up @@ -3,14 +3,20 @@
import java.lang.annotation.Annotation;
import java.util.*;

import com.fasterxml.jackson.annotation.JacksonInject;
import com.fasterxml.jackson.annotation.JsonIgnore;
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
import com.fasterxml.jackson.annotation.JsonInclude;
import com.fasterxml.jackson.annotation.JsonProperty;
import com.fasterxml.jackson.annotation.OptBoolean;

import com.fasterxml.jackson.core.Version;

import com.fasterxml.jackson.databind.*;
import com.fasterxml.jackson.databind.cfg.MapperConfig;
import com.fasterxml.jackson.databind.deser.jdk.StringDeserializer;
import com.fasterxml.jackson.databind.deser.jdk.UntypedObjectDeserializer;
import com.fasterxml.jackson.databind.json.JsonMapper;
import com.fasterxml.jackson.databind.jsontype.NamedType;
import com.fasterxml.jackson.databind.ser.jdk.StringSerializer;
import com.fasterxml.jackson.databind.ser.std.ToStringSerializer;
Expand Down Expand Up @@ -579,4 +585,97 @@ public void testInclusionMerging() throws Exception
assertEquals(JsonInclude.Include.NON_EMPTY, v21.getContentInclusion());
assertEquals(JsonInclude.Include.NON_ABSENT, v21.getValueInclusion());
}

/*
/**********************************************************
/* Introspectors and test for [jackson-modules-base#134]/[databind#962]
/**********************************************************
*/
static class TestIntrospector extends NopAnnotationIntrospector {
@Override
public JacksonInject.Value findInjectableValue(MapperConfig<?> config,
AnnotatedMember m) {
if (m.getRawType() == UnreadableBean.class) {
return JacksonInject.Value.forId("jjj");
}
return null;
}
}

static class TestInjector extends InjectableValues {
@Override
public Object findInjectableValue(Object valueId, DeserializationContext ctxt, BeanProperty forProperty, Object beanInstance) {
if (valueId == "jjj") {
UnreadableBean bean = new UnreadableBean();
bean.setValue(1);
return bean;
}
return null;
}

@Override
public InjectableValues snapshot() {
return this;
}
}

enum SimpleEnum { ONE, TWO }

static class UnreadableBean {
public SimpleEnum value;

public void setValue(SimpleEnum value) {
this.value = value;
}

public void setValue(Integer intValue) {
this.value = SimpleEnum.values()[intValue];
}

public SimpleEnum getValue() {
return value;
}
}

static class ReadableInjectedBean {
public ReadableInjectedBean(@JacksonInject(useInput = OptBoolean.FALSE) UnreadableBean injectBean) {
this.injectBean = injectBean;
}
@JsonProperty
String foo;
@JsonIgnore
UnreadableBean injectBean;
}

static class UnreadableInjectedBean {
public UnreadableInjectedBean(@JacksonInject UnreadableBean injectBean) {
this.injectBean = injectBean;
}
@JsonProperty
private String foo;
@JsonIgnore
private UnreadableBean injectBean;
}

public void testMergingIntrospectorsForInjection() throws Exception {
AnnotationIntrospector testIntrospector = new TestIntrospector();
ObjectMapper mapper = JsonMapper.builder()
.injectableValues(new TestInjector())
.annotationIntrospector(new AnnotationIntrospectorPair(testIntrospector,
new JacksonAnnotationIntrospector()))
.build();
ReadableInjectedBean bean = mapper.readValue("{\"foo\": \"bob\"}", ReadableInjectedBean.class);
assertEquals("bob", bean.foo);
assertEquals(SimpleEnum.TWO, bean.injectBean.value);

boolean successReadingUnreadableInjectedBean;
try {
/*UnreadableInjectedBean noBean =*/ mapper.readValue("{\"foo\": \"bob\"}", UnreadableInjectedBean.class);
successReadingUnreadableInjectedBean = true;
} catch (DatabindException e) {
successReadingUnreadableInjectedBean = false;
assertTrue(e.getMessage().contains("Conflicting setter definitions"));
}
assertFalse(successReadingUnreadableInjectedBean);
}
}

0 comments on commit d066e04

Please sign in to comment.