• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 package com.fasterxml.jackson.databind.objectid;
2 
3 import com.fasterxml.jackson.annotation.*;
4 import com.fasterxml.jackson.databind.*;
5 
6 public class AlwaysAsReferenceFirstTest extends BaseMapTest
7 {
8     // [databind#1255]
9     @JsonPropertyOrder({ "bar1", "bar2" })
10     static class Foo {
11 
12         @JsonIdentityReference(alwaysAsId = true)
13         public Bar bar1;
14 
15         @JsonIdentityReference
16         public Bar bar2;
17     }
18 
19     @JsonIdentityInfo(generator = ObjectIdGenerators.IntSequenceGenerator.class)
20     static class Bar {
21         public int value = 3;
22     }
23 
24     // [databind#1607]
25 
26     @JsonIdentityInfo(generator=ObjectIdGenerators.IntSequenceGenerator.class, property="id")
27     static class Value1607
28     {
29         public int value;
30 
Value1607()31         public Value1607() { this(0); }
Value1607(int v)32         public Value1607(int v) {
33             value = v;
34         }
35 }
36     @JsonIdentityInfo(generator=ObjectIdGenerators.IntSequenceGenerator.class, property="id")
37     @JsonIdentityReference(alwaysAsId=true)
38     static class Value1607ViaClass
39     {
40         public int value;
41 
Value1607ViaClass()42         public Value1607ViaClass() { this(0); }
Value1607ViaClass(int v)43         public Value1607ViaClass(int v) {
44             value = v;
45         }
46     }
47 
48     @JsonPropertyOrder(alphabetic=true)
49     static class ReallyAlwaysContainer
50     {
51         public Value1607ViaClass alwaysClass = new Value1607ViaClass(13);
52 
53         @JsonIdentityReference(alwaysAsId=true)
54         public Value1607 alwaysProp = new Value1607(13);
55     }
56 
57     /*
58     /**********************************************************
59     /* Test methods
60     /**********************************************************
61      */
62 
63     private final ObjectMapper MAPPER = new ObjectMapper();
64 
65     // [databind#1255]
testIssue1255()66     public void testIssue1255() throws Exception
67     {
68         Foo mo = new Foo();
69         mo.bar1 = new Bar();
70         mo.bar2 = mo.bar1;
71 
72         String json = MAPPER.writeValueAsString(mo);
73 
74         Foo result = MAPPER.readValue(json, Foo.class);
75         assertNotNull(result);
76     }
77 
78     // [databind#1607]
testIssue1607()79     public void testIssue1607() throws Exception
80     {
81         String json = MAPPER.writeValueAsString(new ReallyAlwaysContainer());
82         assertEquals(aposToQuotes("{'alwaysClass':1,'alwaysProp':2}"), json);
83     }
84 }
85