• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 package com.fasterxml.jackson.databind.objectid;
2 
3 import com.fasterxml.jackson.annotation.*;
4 
5 import com.fasterxml.jackson.databind.*;
6 import com.fasterxml.jackson.databind.testutil.NoCheckSubTypeValidator;
7 
8 public class ObjectId825Test extends BaseMapTest
9 {
10     @JsonIdentityInfo(generator=ObjectIdGenerators.PropertyGenerator.class, property="oidString")
11     public static class AbstractEntity {
12         public String oidString;
13     }
14 
15     public static class TestA extends AbstractEntity {
16         public TestAbst testAbst;
17         public TestD d;
18     }
19 
20     static class TestAbst extends AbstractEntity { }
21 
22     static class TestC extends TestAbst {
23         public TestD d;
24     }
25 
26     static class TestD extends AbstractEntity { }
27 
28     private final ObjectMapper DEF_TYPING_MAPPER = jsonMapperBuilder()
29             .activateDefaultTyping(NoCheckSubTypeValidator.instance,
30                     ObjectMapper.DefaultTyping.NON_FINAL)
31             .build();
32 
testDeserialize()33     public void testDeserialize() throws Exception {
34         TestA a = new TestA();
35         a.oidString = "oidA";
36 
37         TestC c = new TestC();
38         c.oidString = "oidC";
39 
40         a.testAbst = c;
41 
42         TestD d = new TestD();
43         d.oidString = "oidD";
44 
45         c.d = d;
46         a.d = d;
47 
48         String json = DEF_TYPING_MAPPER.writeValueAsString(a);
49 //        System.out.println("JSON: " + json);
50         TestA testADeserialized = DEF_TYPING_MAPPER.readValue(json, TestA.class);
51 
52         assertNotNull(testADeserialized);
53         assertNotNull(testADeserialized.d);
54         assertEquals("oidD", testADeserialized.d.oidString);
55     }
56 }
57