@@ -9,24 +9,6 @@ public class CaseInsensitiveDeserTest extends BaseMapTest
9
9
static class BaseResponse {
10
10
public int errorCode ;
11
11
public String debugMessage ;
12
-
13
- /*
14
- public String getDebugMessage() {
15
- return debugMessage;
16
- }
17
-
18
- public void setDebugMessage(String debugMessage) {
19
- this.debugMessage = debugMessage;
20
- }
21
-
22
- public int getErrorCode() {
23
- return errorCode;
24
- }
25
-
26
- public void setErrorCode(int errorCode) {
27
- this.errorCode = errorCode;
28
- }
29
- */
30
12
}
31
13
32
14
static class Issue476Bean {
@@ -41,16 +23,20 @@ static class Issue476Type {
41
23
/* Test methods
42
24
/********************************************************
43
25
*/
44
-
45
- // [databind#566]
26
+ private final ObjectMapper INSENSITIVE_MAPPER = new ObjectMapper ();
27
+ {
28
+ INSENSITIVE_MAPPER .enable (MapperFeature .ACCEPT_CASE_INSENSITIVE_PROPERTIES );
29
+
30
+ }
31
+
32
+ // [databind#566]
46
33
public void testCaseInsensitiveDeserialization () throws Exception
47
34
{
48
35
final String JSON = "{\" Value1\" : {\" nAme\" : \" fruit\" , \" vALUe\" : \" apple\" }, \" valUE2\" : {\" NAME\" : \" color\" , \" value\" : \" red\" }}" ;
49
36
50
37
// first, verify default settings which do not accept improper case
51
38
ObjectMapper mapper = new ObjectMapper ();
52
39
assertFalse (mapper .isEnabled (MapperFeature .ACCEPT_CASE_INSENSITIVE_PROPERTIES ));
53
-
54
40
try {
55
41
mapper .readValue (JSON , Issue476Bean .class );
56
42
@@ -61,9 +47,7 @@ public void testCaseInsensitiveDeserialization() throws Exception
61
47
}
62
48
63
49
// Definitely not OK to enable dynamically - the BeanPropertyMap (which is the consumer of this particular feature) gets cached.
64
- mapper = new ObjectMapper ();
65
- mapper .enable (MapperFeature .ACCEPT_CASE_INSENSITIVE_PROPERTIES );
66
- ObjectReader r = mapper .readerFor (Issue476Bean .class );
50
+ ObjectReader r = INSENSITIVE_MAPPER .readerFor (Issue476Bean .class );
67
51
Issue476Bean result = r .readValue (JSON );
68
52
assertEquals (result .value1 .name , "fruit" );
69
53
assertEquals (result .value1 .value , "apple" );
@@ -75,9 +59,7 @@ public void testCaseInsensitive1036() throws Exception
75
59
final String json = "{\" ErrorCode\" :2,\" DebugMessage\" :\" Signature not valid!\" }" ;
76
60
// final String json = "{\"errorCode\":2,\"debugMessage\":\"Signature not valid!\"}";
77
61
78
- ObjectMapper mapper = new ObjectMapper ();
79
- mapper .enable (MapperFeature .ACCEPT_CASE_INSENSITIVE_PROPERTIES );
80
- BaseResponse response = mapper .readValue (json , BaseResponse .class );
62
+ BaseResponse response = INSENSITIVE_MAPPER .readValue (json , BaseResponse .class );
81
63
assertEquals (2 , response .errorCode );
82
64
assertEquals ("Signature not valid!" , response .debugMessage );
83
65
}
0 commit comments