• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 package com.fasterxml.jackson.failing;
2 
3 import java.util.Objects;
4 
5 import com.fasterxml.jackson.annotation.*;
6 
7 import com.fasterxml.jackson.databind.*;
8 
9 // Not sure if [databind#2572] is actually a bug, but behavior in 2.9 was
10 // different from 2.10 in that no exception thrown and databind quietly just
11 // left `null` for Beans as `null` even if "EMPTY" was indicated by configuration.
12 public class JsonSetter2572Test extends BaseMapTest
13 {
14     static class Outer {
15         @JsonProperty("inner")
16         final Inner inner;
17 
18         @JsonCreator
Outer(@sonProperty"inner") Inner inner)19         public Outer(@JsonProperty("inner") Inner inner) {
20             this.inner = Objects.requireNonNull(inner, "inner");
21         }
22     }
23 
24     static class Inner {
25         @JsonProperty("field")
26         final String field;
27 
28         @JsonCreator
Inner(@sonProperty"field") String field)29         public Inner(@JsonProperty("field") String field) {
30             this.field = field;
31         }
32     }
33 
testSetterWithEmpty()34     public void testSetterWithEmpty() throws Exception {
35         /*
36         ObjectMapper mapper = newObjectMapper()
37                 .setDefaultSetterInfo(JsonSetter.Value.construct(Nulls.AS_EMPTY, Nulls.AS_EMPTY));
38                 */
39         ObjectMapper mapper = jsonMapperBuilder()
40                 .defaultSetterInfo(JsonSetter.Value.construct(Nulls.AS_EMPTY, Nulls.AS_EMPTY))
41                 .build();
42 
43         String json = mapper.writeValueAsString(new Outer(new Inner("inner")));
44         Outer result = mapper.readValue(json, Outer.class);
45         assertNotNull(result);
46         assertNotNull(result.inner); // converted to "empty" bean
47 
48 //System.err.println("Final -> "+mapper.writeValueAsString(result));
49     }
50 }
51