-
-
Notifications
You must be signed in to change notification settings - Fork 221
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add a simple test to verify that case-insensitive handling works for …
…regular cases (wrt #273)
- Loading branch information
1 parent
8de0cad
commit b54627d
Showing
2 changed files
with
79 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
71 changes: 71 additions & 0 deletions
71
src/test/java/com/fasterxml/jackson/dataformat/xml/deser/CaseInsensitiveDeserTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
package com.fasterxml.jackson.dataformat.xml.deser; | ||
|
||
import com.fasterxml.jackson.annotation.JsonCreator; | ||
import com.fasterxml.jackson.annotation.JsonProperty; | ||
|
||
import com.fasterxml.jackson.databind.*; | ||
import com.fasterxml.jackson.databind.exc.UnrecognizedPropertyException; | ||
import com.fasterxml.jackson.dataformat.xml.XmlMapper; | ||
import com.fasterxml.jackson.dataformat.xml.XmlTestBase; | ||
|
||
public class CaseInsensitiveDeserTest extends XmlTestBase | ||
{ | ||
// [databind#1036] | ||
static class BaseResponse { | ||
public int errorCode; | ||
public String debugMessage; | ||
} | ||
|
||
// [databind#1438] | ||
static class InsensitiveCreator | ||
{ | ||
int v; | ||
|
||
@JsonCreator | ||
public InsensitiveCreator(@JsonProperty("value") int v0) { | ||
v = v0; | ||
} | ||
} | ||
|
||
/* | ||
/******************************************************** | ||
/* Test methods | ||
/******************************************************** | ||
*/ | ||
|
||
private final ObjectMapper MAPPER = newObjectMapper(); | ||
|
||
private final ObjectMapper INSENSITIVE_MAPPER = newObjectMapper(); | ||
{ | ||
INSENSITIVE_MAPPER.enable(MapperFeature.ACCEPT_CASE_INSENSITIVE_PROPERTIES); | ||
|
||
} | ||
|
||
// [databind#1036] | ||
public void testCaseInsensitive1036() throws Exception | ||
{ | ||
final String DOC = | ||
"<BaseResponse><ErrorCode>2</ErrorCode><DebugMessage>Signature not valid!</DebugMessage></BaseResponse>"; | ||
|
||
// Ok with insensitive | ||
BaseResponse response = INSENSITIVE_MAPPER.readValue(DOC, BaseResponse.class); | ||
assertEquals(2, response.errorCode); | ||
assertEquals("Signature not valid!", response.debugMessage); | ||
|
||
// but not without | ||
try { | ||
MAPPER.readValue(DOC, BaseResponse.class); | ||
fail("Should not pass"); | ||
} catch (UnrecognizedPropertyException e) { | ||
verifyException(e, "ErrorCode"); | ||
} | ||
} | ||
|
||
// [databind#1438] | ||
public void testCreatorWithInsensitive() throws Exception | ||
{ | ||
final String DOC = aposToQuotes("<root><VALUE>3</VALUE></root>"); | ||
InsensitiveCreator bean = INSENSITIVE_MAPPER.readValue(DOC, InsensitiveCreator.class); | ||
assertEquals(3, bean.v); | ||
} | ||
} |