1 package com.fasterxml.jackson.failing; 2 3 import com.fasterxml.jackson.annotation.*; 4 5 import com.fasterxml.jackson.databind.*; 6 7 // [databind#2465] 8 public class JacksonInject2465Test extends BaseMapTest 9 { 10 // [databind#2465] 11 public static final class TestCase2465 { 12 // 17-Apr-2020, tatu: Forcing this to be ignored will work around the 13 // problem, but this really should not be necessary. 14 // @JsonIgnore 15 private final Internal2465 str; 16 private final int id; 17 18 @JsonCreator TestCase2465(@acksonInjectuseInput = OptBoolean.FALSE) Internal2465 str, @JsonProperty("id") int id)19 public TestCase2465(@JacksonInject(useInput = OptBoolean.FALSE) Internal2465 str, 20 @JsonProperty("id") int id) { 21 this.str = str; 22 this.id = id; 23 } 24 fetchId()25 public int fetchId() { return id; } fetchInternal()26 public Internal2465 fetchInternal() { return str; } 27 } 28 29 public static final class Internal2465 { 30 final String val; 31 Internal2465(String val)32 public Internal2465(String val) { 33 this.val = val; 34 } 35 } 36 37 // [databind#2465] testInjectWithCreator()38 public void testInjectWithCreator() throws Exception 39 { 40 ObjectMapper mapper = jsonMapperBuilder() 41 .defaultSetterInfo(JsonSetter.Value.construct(Nulls.AS_EMPTY, Nulls.AS_EMPTY)) 42 .build(); 43 mapper.setVisibility(mapper.getVisibilityChecker().withVisibility(PropertyAccessor.FIELD, 44 JsonAutoDetect.Visibility.ANY)); 45 46 final Internal2465 injected = new Internal2465("test"); 47 TestCase2465 o = mapper.readerFor(TestCase2465.class) 48 .with(new InjectableValues.Std().addValue(Internal2465.class, injected)) 49 .readValue("{\"id\":3}"); 50 assertEquals(3, o.fetchId()); 51 assertNotNull(o.fetchInternal()); 52 } 53 } 54