Skip to content

Commit 5b6e3f6

Browse files
committed
Add (failing) test #1438
1 parent d0cfb64 commit 5b6e3f6

File tree

2 files changed

+46
-27
lines changed

2 files changed

+46
-27
lines changed

src/test/java/com/fasterxml/jackson/databind/misc/CaseInsensitiveDeserTest.java

+9-27
Original file line numberDiff line numberDiff line change
@@ -9,24 +9,6 @@ public class CaseInsensitiveDeserTest extends BaseMapTest
99
static class BaseResponse {
1010
public int errorCode;
1111
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-
*/
3012
}
3113

3214
static class Issue476Bean {
@@ -41,16 +23,20 @@ static class Issue476Type {
4123
/* Test methods
4224
/********************************************************
4325
*/
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]
4633
public void testCaseInsensitiveDeserialization() throws Exception
4734
{
4835
final String JSON = "{\"Value1\" : {\"nAme\" : \"fruit\", \"vALUe\" : \"apple\"}, \"valUE2\" : {\"NAME\" : \"color\", \"value\" : \"red\"}}";
4936

5037
// first, verify default settings which do not accept improper case
5138
ObjectMapper mapper = new ObjectMapper();
5239
assertFalse(mapper.isEnabled(MapperFeature.ACCEPT_CASE_INSENSITIVE_PROPERTIES));
53-
5440
try {
5541
mapper.readValue(JSON, Issue476Bean.class);
5642

@@ -61,9 +47,7 @@ public void testCaseInsensitiveDeserialization() throws Exception
6147
}
6248

6349
// 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);
6751
Issue476Bean result = r.readValue(JSON);
6852
assertEquals(result.value1.name, "fruit");
6953
assertEquals(result.value1.value, "apple");
@@ -75,9 +59,7 @@ public void testCaseInsensitive1036() throws Exception
7559
final String json = "{\"ErrorCode\":2,\"DebugMessage\":\"Signature not valid!\"}";
7660
// final String json = "{\"errorCode\":2,\"debugMessage\":\"Signature not valid!\"}";
7761

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);
8163
assertEquals(2, response.errorCode);
8264
assertEquals("Signature not valid!", response.debugMessage);
8365
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
package com.fasterxml.jackson.failing;
2+
3+
import com.fasterxml.jackson.annotation.JsonCreator;
4+
import com.fasterxml.jackson.annotation.JsonProperty;
5+
import com.fasterxml.jackson.databind.*;
6+
7+
public class CaseInsensitiveDeser1438Test extends BaseMapTest
8+
{
9+
// [databind#1438]
10+
static class InsensitiveCreator
11+
{
12+
int v;
13+
14+
@JsonCreator
15+
public InsensitiveCreator(@JsonProperty("value") int v0) {
16+
v = v0;
17+
}
18+
}
19+
/*
20+
/********************************************************
21+
/* Test methods
22+
/********************************************************
23+
*/
24+
private final ObjectMapper INSENSITIVE_MAPPER = new ObjectMapper();
25+
{
26+
INSENSITIVE_MAPPER.enable(MapperFeature.ACCEPT_CASE_INSENSITIVE_PROPERTIES);
27+
28+
}
29+
30+
// [databind#1438]
31+
public void testCreatorWithInsensitive() throws Exception
32+
{
33+
final String json = aposToQuotes("{'VALUE':3}");
34+
InsensitiveCreator bean = INSENSITIVE_MAPPER.readValue(json, InsensitiveCreator.class);
35+
assertEquals(3, bean.v);
36+
}
37+
}

0 commit comments

Comments
 (0)