Skip to content

Commit b54627d

Browse files
committed
Add a simple test to verify that case-insensitive handling works for regular cases (wrt #273)
1 parent 8de0cad commit b54627d

File tree

2 files changed

+79
-2
lines changed

2 files changed

+79
-2
lines changed

src/test/java/com/fasterxml/jackson/dataformat/xml/XmlTestBase.java

+8-2
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77

88
import com.fasterxml.jackson.annotation.JsonPropertyOrder;
99
import com.fasterxml.jackson.core.*;
10+
import com.fasterxml.jackson.databind.ObjectMapper;
1011
import com.fasterxml.jackson.dataformat.xml.annotation.JacksonXmlProperty;
1112

1213
public abstract class XmlTestBase
@@ -182,13 +183,17 @@ protected XmlTestBase() {
182183
super();
183184
}
184185

186+
protected static ObjectMapper newObjectMapper() {
187+
return new XmlMapper();
188+
}
189+
185190
protected XmlMapper xmlMapper(boolean useListWrapping)
186191
{
187192
JacksonXmlModule module = new JacksonXmlModule();
188193
module.setDefaultUseWrapper(useListWrapping);
189194
return new XmlMapper(module);
190195
}
191-
196+
192197
/*
193198
/**********************************************************
194199
/* Additional assertion methods
@@ -246,7 +251,8 @@ protected void verifyException(Throwable e, String... matches)
246251
return;
247252
}
248253
}
249-
fail("Expected an exception with one of substrings ("+Arrays.asList(matches)+"): got one with message \""+msg+"\"");
254+
fail("Expected an exception with one of substrings ("+Arrays.asList(matches)+"): got one ("+
255+
e.getClass().getName()+") with message \""+msg+"\"");
250256
}
251257

252258
/*
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
package com.fasterxml.jackson.dataformat.xml.deser;
2+
3+
import com.fasterxml.jackson.annotation.JsonCreator;
4+
import com.fasterxml.jackson.annotation.JsonProperty;
5+
6+
import com.fasterxml.jackson.databind.*;
7+
import com.fasterxml.jackson.databind.exc.UnrecognizedPropertyException;
8+
import com.fasterxml.jackson.dataformat.xml.XmlMapper;
9+
import com.fasterxml.jackson.dataformat.xml.XmlTestBase;
10+
11+
public class CaseInsensitiveDeserTest extends XmlTestBase
12+
{
13+
// [databind#1036]
14+
static class BaseResponse {
15+
public int errorCode;
16+
public String debugMessage;
17+
}
18+
19+
// [databind#1438]
20+
static class InsensitiveCreator
21+
{
22+
int v;
23+
24+
@JsonCreator
25+
public InsensitiveCreator(@JsonProperty("value") int v0) {
26+
v = v0;
27+
}
28+
}
29+
30+
/*
31+
/********************************************************
32+
/* Test methods
33+
/********************************************************
34+
*/
35+
36+
private final ObjectMapper MAPPER = newObjectMapper();
37+
38+
private final ObjectMapper INSENSITIVE_MAPPER = newObjectMapper();
39+
{
40+
INSENSITIVE_MAPPER.enable(MapperFeature.ACCEPT_CASE_INSENSITIVE_PROPERTIES);
41+
42+
}
43+
44+
// [databind#1036]
45+
public void testCaseInsensitive1036() throws Exception
46+
{
47+
final String DOC =
48+
"<BaseResponse><ErrorCode>2</ErrorCode><DebugMessage>Signature not valid!</DebugMessage></BaseResponse>";
49+
50+
// Ok with insensitive
51+
BaseResponse response = INSENSITIVE_MAPPER.readValue(DOC, BaseResponse.class);
52+
assertEquals(2, response.errorCode);
53+
assertEquals("Signature not valid!", response.debugMessage);
54+
55+
// but not without
56+
try {
57+
MAPPER.readValue(DOC, BaseResponse.class);
58+
fail("Should not pass");
59+
} catch (UnrecognizedPropertyException e) {
60+
verifyException(e, "ErrorCode");
61+
}
62+
}
63+
64+
// [databind#1438]
65+
public void testCreatorWithInsensitive() throws Exception
66+
{
67+
final String DOC = aposToQuotes("<root><VALUE>3</VALUE></root>");
68+
InsensitiveCreator bean = INSENSITIVE_MAPPER.readValue(DOC, InsensitiveCreator.class);
69+
assertEquals(3, bean.v);
70+
}
71+
}

0 commit comments

Comments
 (0)