1
1
package com .fasterxml .jackson .databind .deser .filter ;
2
2
3
3
import java .beans .ConstructorProperties ;
4
- import java .io .IOException ;
5
4
5
+ import com .fasterxml .jackson .annotation .JsonIgnoreProperties ;
6
6
import com .fasterxml .jackson .annotation .JsonProperty ;
7
7
import com .fasterxml .jackson .databind .BaseMapTest ;
8
8
import com .fasterxml .jackson .databind .ObjectMapper ;
9
9
10
10
public class ReadOnlyDeser1890Test
11
11
extends BaseMapTest
12
12
{
13
- public static class PersonAnnotations {
13
+ // [databind#95]
14
+ @ JsonIgnoreProperties (value ={ "computed" }, allowGetters =true )
15
+ static class ReadOnly95Bean
16
+ {
17
+ public int value = 3 ;
18
+
19
+ public int getComputed () { return 32 ; }
20
+ }
21
+
22
+ // [databind#1890]
23
+ static class PersonAnnotations {
14
24
public String name ;
15
25
@ JsonProperty (access = JsonProperty .Access .READ_ONLY )
16
26
private TestEnum testEnum = TestEnum .DEFAULT ;
@@ -30,9 +40,9 @@ public TestEnum getTestEnum() {
30
40
public void setTestEnum (TestEnum testEnum ) {
31
41
this .testEnum = testEnum ;
32
42
}
33
- }
43
+ }
34
44
35
- public static class Person {
45
+ static class Person {
36
46
public String name ;
37
47
@ JsonProperty (access = JsonProperty .Access .READ_ONLY )
38
48
private TestEnum testEnum = TestEnum .DEFAULT ;
@@ -63,30 +73,43 @@ enum TestEnum{
63
73
/**********************************************************
64
74
*/
65
75
66
- private final ObjectMapper MAPPER = objectMapper ();
76
+ private final ObjectMapper MAPPER = newJsonMapper ();
77
+
78
+ // [databind#95]
79
+ public void testReadOnlyProps95 () throws Exception
80
+ {
81
+ ObjectMapper m = new ObjectMapper ();
82
+ String json = m .writeValueAsString (new ReadOnly95Bean ());
83
+ if (json .indexOf ("computed" ) < 0 ) {
84
+ fail ("Should have property 'computed', didn't: " +json );
85
+ }
86
+ ReadOnly95Bean bean = m .readValue (json , ReadOnly95Bean .class );
87
+ assertNotNull (bean );
88
+ }
67
89
68
- public void testDeserializeAnnotationsOneField () throws IOException {
90
+ // [databind#1890]
91
+ public void testDeserializeAnnotationsOneField () throws Exception {
69
92
PersonAnnotations person = MAPPER .readValue ("{\" testEnum\" :\" \" }" , PersonAnnotations .class );
70
93
// can not remain as is, so becomes `null`
71
94
assertEquals (null , person .getTestEnum ());
72
95
assertNull (person .name );
73
96
}
74
97
75
- public void testDeserializeAnnotationsTwoFields () throws IOException {
98
+ public void testDeserializeAnnotationsTwoFields () throws Exception {
76
99
PersonAnnotations person = MAPPER .readValue ("{\" testEnum\" :\" \" ,\" name\" :\" changyong\" }" ,
77
100
PersonAnnotations .class );
78
101
// can not remain as is, so becomes `null`
79
102
assertEquals (null , person .getTestEnum ());
80
103
assertEquals ("changyong" , person .name );
81
104
}
82
105
83
- public void testDeserializeOneField () throws IOException {
106
+ public void testDeserializeOneField () throws Exception {
84
107
Person person = MAPPER .readValue ("{\" testEnum\" :\" \" }" , Person .class );
85
108
assertEquals (TestEnum .DEFAULT , person .getTestEnum ());
86
109
assertNull (person .name );
87
110
}
88
111
89
- public void testDeserializeTwoFields () throws IOException {
112
+ public void testDeserializeTwoFields () throws Exception {
90
113
Person person = MAPPER .readValue ("{\" testEnum\" :\" \" ,\" name\" :\" changyong\" }" ,
91
114
Person .class );
92
115
assertEquals (TestEnum .DEFAULT , person .getTestEnum ());
0 commit comments