aboutsummaryrefslogtreecommitdiff
path: root/src/test/java/com/fasterxml/jackson/databind/introspect/TestPropertyRename.java
blob: b6b05f9e9e6e3e3515cecb6680a4be77ac7f2e17 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
package com.fasterxml.jackson.databind.introspect;

import com.fasterxml.jackson.annotation.*;
import com.fasterxml.jackson.databind.*;

/**
 * Unit tests verifying handling of potential and actual
 * conflicts, regarding property handling.
 */
public class TestPropertyRename extends BaseMapTest
{
    static class Bean323WithIgnore { 
        @JsonIgnore
        private int a;

        public Bean323WithIgnore(@JsonProperty("a") final int a ) {
            this.a = a;
        }

        @JsonProperty("b")
        private int getA () {
            return a;
        }
    }    

    @JsonPropertyOrder({ "a","b" })
    static class Bean323WithExplicitCleave1 { 
        @JsonProperty("a")
        private int a;

        public Bean323WithExplicitCleave1(@JsonProperty("a") final int a ) {
            this.a = a;
        }

        @JsonProperty("b")
        private int getA () {
            return a;
        }
    } 

    @JsonPropertyOrder({ "a","b" })
    static class Bean323WithExplicitCleave2 { 
        @JsonProperty("b")
        private int a;

        public Bean323WithExplicitCleave2(@JsonProperty("a") final int a ) {
            this.a = a;
        }

        @JsonProperty("b")
        private int getA () {
            return a;
        }
    }    
   
    /*
    /**********************************************************
    /* Test methods
    /**********************************************************
     */

    public void testCreatorPropRenameWithIgnore() throws Exception
    {
        Bean323WithIgnore input = new Bean323WithIgnore(7);
        assertEquals("{\"b\":7}", objectWriter().writeValueAsString(input));
    }

    public void testCreatorPropRenameWithCleave() throws Exception
    {
        assertEquals("{\"a\":7,\"b\":7}",
        		objectWriter().writeValueAsString(new Bean323WithExplicitCleave1(7)));
        // note: 'a' NOT included as only ctor property found for it, no getter/field
        assertEquals("{\"b\":7}", objectWriter().writeValueAsString(new Bean323WithExplicitCleave2(7)));
    }
}