-
-
Notifications
You must be signed in to change notification settings - Fork 1.4k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
fe5ed28
commit 60a0c25
Showing
1 changed file
with
62 additions
and
0 deletions.
There are no files selected for viewing
62 changes: 62 additions & 0 deletions
62
src/test/java/com/fasterxml/jackson/failing/CaseInsensitiveDeser953Test.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,62 @@ | ||
package com.fasterxml.jackson.failing; | ||
|
||
import java.util.Locale; | ||
|
||
import com.fasterxml.jackson.annotation.JsonProperty; | ||
import com.fasterxml.jackson.databind.*; | ||
|
||
public class CaseInsensitiveDeser953Test extends BaseMapTest | ||
{ | ||
static class Id953 { | ||
@JsonProperty("someId") | ||
public int someId; | ||
} | ||
|
||
private final Locale LOCALE_EN = new Locale("en", "US"); | ||
|
||
private final ObjectMapper INSENSITIVE_MAPPER_EN = jsonMapperBuilder() | ||
.enable(MapperFeature.ACCEPT_CASE_INSENSITIVE_PROPERTIES) | ||
.defaultLocale(LOCALE_EN) | ||
.build(); | ||
|
||
private final Locale LOCALE_TR = new Locale("tr", "TR"); | ||
|
||
private final ObjectMapper INSENSITIVE_MAPPER_TR = jsonMapperBuilder() | ||
.enable(MapperFeature.ACCEPT_CASE_INSENSITIVE_PROPERTIES) | ||
.defaultLocale(LOCALE_TR) | ||
.build(); | ||
|
||
public void testTurkishILetterDeserializationWithEn() throws Exception { | ||
_testTurkishILetterDeserialization(INSENSITIVE_MAPPER_EN, LOCALE_EN); | ||
} | ||
|
||
public void testTurkishILetterDeserializationWithTr() throws Exception { | ||
_testTurkishILetterDeserialization(INSENSITIVE_MAPPER_TR, LOCALE_TR); | ||
} | ||
|
||
private void _testTurkishILetterDeserialization(ObjectMapper mapper, Locale locale) throws Exception | ||
{ | ||
// Sanity check first | ||
assertEquals(locale, mapper.getDeserializationConfig().getLocale()); | ||
|
||
final String ORIGINAL_KEY = "someId"; | ||
|
||
Id953 result; | ||
result = mapper.readValue("{\""+ORIGINAL_KEY+"\":1}", Id953.class); | ||
assertEquals(1, result.someId); | ||
|
||
result = mapper.readValue("{\""+ORIGINAL_KEY.toUpperCase(locale)+"\":1}", Id953.class); | ||
assertEquals(1, result.someId); | ||
|
||
result = mapper.readValue("{\""+ORIGINAL_KEY.toLowerCase(locale)+"\":1}", Id953.class); | ||
assertEquals(1, result.someId); | ||
|
||
// and finally round-trip too... | ||
final Id953 input = new Id953(); | ||
input.someId = 1; | ||
final String json = mapper.writeValueAsString(input); | ||
|
||
result = mapper.readValue(json, Id953.class); | ||
assertEquals(1, result.someId); | ||
} | ||
} |