• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 package com.fasterxml.jackson.failing;
2 
3 import com.fasterxml.jackson.annotation.JsonUnwrapped;
4 import com.fasterxml.jackson.databind.*;
5 
6 public class UnwrappedCaching2461Test extends BaseMapTest
7 {
8     // [databind#2461]
9     static class Base {
10         public String id;
11 
Base(String id)12         Base(String id) {
13             this.id = id;
14         }
15     }
16 
17     static class InnerContainer {
18         @JsonUnwrapped(prefix = "base.")
19         public Base base;
20 
InnerContainer(Base base)21         InnerContainer(Base base) {
22             this.base = base;
23         }
24     }
25 
26     static class OuterContainer {
27         @JsonUnwrapped(prefix = "container.")
28         public InnerContainer container;
29 
OuterContainer(InnerContainer container)30         OuterContainer(InnerContainer container) {
31             this.container = container;
32         }
33     }
34 
35     // [databind#2461]
testUnwrappedCaching()36     public void testUnwrappedCaching() throws Exception {
37         final InnerContainer inner = new InnerContainer(new Base("12345"));
38         final OuterContainer outer = new OuterContainer(inner);
39 
40         final String EXP_INNER = "{\"base.id\":\"12345\"}";
41         final String EXP_OUTER = "{\"container.base.id\":\"12345\"}";
42 
43         final ObjectMapper mapperOrder1 = newJsonMapper();
44         assertEquals(EXP_OUTER, mapperOrder1.writeValueAsString(outer));
45         assertEquals(EXP_INNER, mapperOrder1.writeValueAsString(inner));
46         assertEquals(EXP_OUTER, mapperOrder1.writeValueAsString(outer));
47 
48         final ObjectMapper mapperOrder2 = newJsonMapper();
49         assertEquals(EXP_INNER, mapperOrder2.writeValueAsString(inner));
50         //  Will fail here
51         assertEquals(EXP_OUTER, mapperOrder2.writeValueAsString(outer));
52     }
53 }
54