1
1
package com .fasterxml .jackson .databind .deser .filter ;
2
2
3
+ import java .util .Set ;
4
+
3
5
import com .fasterxml .jackson .annotation .JsonIgnoreProperties ;
4
6
import com .fasterxml .jackson .annotation .JsonProperty ;
5
7
@@ -12,33 +14,57 @@ static class Person {
12
14
13
15
@ JsonProperty ("person_z" ) // renaming this to person_p works
14
16
@ JsonIgnoreProperties ({"person_z" }) // renaming this to person_p works
15
- // public Set<Person> personZ;
16
17
public Person personZ ;
17
18
}
18
19
20
+ static class Persons {
21
+ public String name ;
22
+
23
+ @ JsonProperty ("person_z" ) // renaming this to person_p works
24
+ @ JsonIgnoreProperties ({"person_z" }) // renaming this to person_p works
25
+ public Set <Persons > personZ ;
26
+ }
27
+
28
+ /*
29
+ /**********************************************************************
30
+ /* Test methods
31
+ /**********************************************************************
32
+ */
33
+
34
+ private final ObjectMapper MAPPER = newObjectMapper ();
35
+
19
36
public void testRecursiveForDeser () throws Exception
20
37
{
21
38
String st = aposToQuotes ("{ 'name': 'admin',\n "
22
- // + " 'person_z': [ { 'name': 'admin' } ]"
23
- + " 'person_z': { 'name': 'admin' }"
39
+ + " 'person_z': { 'name': 'wyatt' }"
24
40
+ "}" );
41
+ Person result = MAPPER .readValue (st , Person .class );
42
+ assertEquals ("admin" , result .name );
43
+ assertNotNull (result .personZ );
44
+ assertEquals ("wyatt" , result .personZ .name );
45
+ }
25
46
26
- ObjectMapper mapper = newObjectMapper ();
27
- Person result = mapper .readValue (st , Person .class );
47
+ public void testRecursiveWithCollectionDeser () throws Exception
48
+ {
49
+ String st = aposToQuotes ("{ 'name': 'admin',\n "
50
+ + " 'person_z': [ { 'name': 'Foor' }, { 'name' : 'Bar' } ]"
51
+ + "}" );
52
+ Persons result = MAPPER .readValue (st , Persons .class );
28
53
assertEquals ("admin" , result .name );
54
+ assertNotNull (result .personZ );
55
+ assertEquals (2 , result .personZ .size ());
29
56
}
30
57
31
58
public void testRecursiveForSer () throws Exception
32
59
{
33
- ObjectMapper mapper = newObjectMapper ();
34
60
Person input = new Person ();
35
61
input .name = "Bob" ;
36
62
Person p2 = new Person ();
37
63
p2 .name = "Bill" ;
38
64
input .personZ = p2 ;
39
65
p2 .personZ = input ;
40
66
41
- String json = mapper .writeValueAsString (input );
67
+ String json = MAPPER .writeValueAsString (input );
42
68
assertNotNull (json );
43
69
}
44
70
}
0 commit comments