• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 package com.fasterxml.jackson.databind.introspect;
2 
3 import com.fasterxml.jackson.annotation.*;
4 import com.fasterxml.jackson.databind.*;
5 
6 /**
7  * Unit tests verifying handling of potential and actual
8  * conflicts, regarding property handling.
9  */
10 public class TestPropertyRename extends BaseMapTest
11 {
12     static class Bean323WithIgnore {
13         @JsonIgnore
14         private int a;
15 
Bean323WithIgnore(@sonProperty"a") final int a )16         public Bean323WithIgnore(@JsonProperty("a") final int a ) {
17             this.a = a;
18         }
19 
20         @JsonProperty("b")
getA()21         private int getA () {
22             return a;
23         }
24     }
25 
26     @JsonPropertyOrder({ "a","b" })
27     static class Bean323WithExplicitCleave1 {
28         @JsonProperty("a")
29         private int a;
30 
Bean323WithExplicitCleave1(@sonProperty"a") final int a )31         public Bean323WithExplicitCleave1(@JsonProperty("a") final int a ) {
32             this.a = a;
33         }
34 
35         @JsonProperty("b")
getA()36         private int getA () {
37             return a;
38         }
39     }
40 
41     @JsonPropertyOrder({ "a","b" })
42     static class Bean323WithExplicitCleave2 {
43         @JsonProperty("b")
44         private int a;
45 
Bean323WithExplicitCleave2(@sonProperty"a") final int a )46         public Bean323WithExplicitCleave2(@JsonProperty("a") final int a ) {
47             this.a = a;
48         }
49 
50         @JsonProperty("b")
getA()51         private int getA () {
52             return a;
53         }
54     }
55 
56     /*
57     /**********************************************************
58     /* Test methods
59     /**********************************************************
60      */
61 
testCreatorPropRenameWithIgnore()62     public void testCreatorPropRenameWithIgnore() throws Exception
63     {
64         Bean323WithIgnore input = new Bean323WithIgnore(7);
65         assertEquals("{\"b\":7}", objectWriter().writeValueAsString(input));
66     }
67 
testCreatorPropRenameWithCleave()68     public void testCreatorPropRenameWithCleave() throws Exception
69     {
70         assertEquals("{\"a\":7,\"b\":7}",
71         		objectWriter().writeValueAsString(new Bean323WithExplicitCleave1(7)));
72         // note: 'a' NOT included as only ctor property found for it, no getter/field
73         assertEquals("{\"b\":7}", objectWriter().writeValueAsString(new Bean323WithExplicitCleave2(7)));
74     }
75 }
76