3
3
import java .io .*;
4
4
5
5
import com .fasterxml .jackson .annotation .*;
6
-
6
+ import com . fasterxml . jackson . annotation . JsonAutoDetect . Visibility ;
7
7
import com .fasterxml .jackson .core .*;
8
8
import com .fasterxml .jackson .databind .*;
9
9
import com .fasterxml .jackson .databind .annotation .JsonDeserialize ;
18
18
public class TestBasicAnnotations
19
19
extends BaseMapTest
20
20
{
21
- /*
22
- /**********************************************************
23
- /* Annotated helper classes
24
- /**********************************************************
25
- */
26
-
27
21
/// Class for testing {@link JsonProperty} annotations
28
22
final static class SizeClassSetter
29
23
{
@@ -88,6 +82,24 @@ static class BeanWithDeserialize {
88
82
@ JsonDeserialize protected int a ;
89
83
}
90
84
85
+ @ JsonAutoDetect (setterVisibility =Visibility .NONE )
86
+ final static class Dummy { }
87
+
88
+ final static class EmptyDummy { }
89
+
90
+ static class AnnoBean {
91
+ int value = 3 ;
92
+
93
+ @ JsonProperty ("y" )
94
+ public void setX (int v ) { value = v ; }
95
+ }
96
+
97
+ enum Alpha { A , B , C ; }
98
+
99
+ public static class SimpleBean {
100
+ public int x , y ;
101
+ }
102
+
91
103
/*
92
104
/**********************************************************
93
105
/* Other helper classes
@@ -104,10 +116,10 @@ public int[] deserialize(JsonParser jp, DeserializationContext ctxt)
104
116
return new int [] { jp .getIntValue () };
105
117
}
106
118
}
107
-
119
+
108
120
/*
109
121
/**********************************************************
110
- /* Test methods
122
+ /* Test methods, basic
111
123
/**********************************************************
112
124
*/
113
125
@@ -168,4 +180,46 @@ public void testIssue442PrivateUnwrapped() throws Exception
168
180
Issue442Bean bean = MAPPER .readValue ("{\" i\" :5}" , Issue442Bean .class );
169
181
assertEquals (5 , bean .w .i );
170
182
}
183
+
184
+ /*
185
+ /**********************************************************
186
+ /* Test methods, annotations disabled
187
+ /**********************************************************
188
+ */
189
+
190
+ public void testAnnotationsDisabled () throws Exception
191
+ {
192
+ // first: verify that annotation introspection is enabled by default
193
+ ObjectMapper m = new ObjectMapper ();
194
+ assertTrue (m .getDeserializationConfig ().isEnabled (MapperFeature .USE_ANNOTATIONS ));
195
+ // with annotations, property is renamed
196
+ AnnoBean bean = m .readValue ("{ \" y\" : 0 }" , AnnoBean .class );
197
+ assertEquals (0 , bean .value );
198
+
199
+ m = new ObjectMapper ();
200
+ m .configure (MapperFeature .USE_ANNOTATIONS , false );
201
+ // without annotations, should default to default bean-based name...
202
+ bean = m .readValue ("{ \" x\" : 0 }" , AnnoBean .class );
203
+ assertEquals (0 , bean .value );
204
+ }
205
+
206
+ public void testEnumsWhenDisabled () throws Exception
207
+ {
208
+ ObjectMapper m = new ObjectMapper ();
209
+ assertEquals (Alpha .B , m .readValue (quote ("B" ), Alpha .class ));
210
+
211
+ m = new ObjectMapper ();
212
+ m .configure (MapperFeature .USE_ANNOTATIONS , false );
213
+ // should still use the basic name handling here
214
+ assertEquals (Alpha .B , m .readValue (quote ("B" ), Alpha .class ));
215
+ }
216
+
217
+ public void testNoAccessOverrides () throws Exception
218
+ {
219
+ ObjectMapper m = new ObjectMapper ();
220
+ m .disable (MapperFeature .CAN_OVERRIDE_ACCESS_MODIFIERS );
221
+ SimpleBean bean = m .readValue ("{\" x\" :1,\" y\" :2}" , SimpleBean .class );
222
+ assertEquals (1 , bean .x );
223
+ assertEquals (2 , bean .y );
224
+ }
171
225
}
0 commit comments