• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 package com.fasterxml.jackson.databind.misc;
2 
3 import java.util.Locale;
4 
5 import com.fasterxml.jackson.annotation.JsonProperty;
6 import com.fasterxml.jackson.databind.*;
7 
8 public class CaseInsensitiveDeser953Test extends BaseMapTest
9 {
10     static class Id953 {
11         @JsonProperty("someId")
12         public int someId;
13     }
14 
15     private final Locale LOCALE_EN = new Locale("en", "US");
16 
17     private final ObjectMapper INSENSITIVE_MAPPER_EN = jsonMapperBuilder()
18             .enable(MapperFeature.ACCEPT_CASE_INSENSITIVE_PROPERTIES)
19             .defaultLocale(LOCALE_EN)
20             .build();
21 
22     private final Locale LOCALE_TR = new Locale("tr", "TR");
23 
24     private final ObjectMapper INSENSITIVE_MAPPER_TR = jsonMapperBuilder()
25             .enable(MapperFeature.ACCEPT_CASE_INSENSITIVE_PROPERTIES)
26             .defaultLocale(LOCALE_TR)
27             .build();
28 
testTurkishILetterDeserializationWithEn()29     public void testTurkishILetterDeserializationWithEn() throws Exception {
30         _testTurkishILetterDeserialization(INSENSITIVE_MAPPER_EN, LOCALE_EN);
31     }
32 
testTurkishILetterDeserializationWithTr()33     public void testTurkishILetterDeserializationWithTr() throws Exception {
34         _testTurkishILetterDeserialization(INSENSITIVE_MAPPER_TR, LOCALE_TR);
35     }
36 
_testTurkishILetterDeserialization(ObjectMapper mapper, Locale locale)37     private void _testTurkishILetterDeserialization(ObjectMapper mapper, Locale locale) throws Exception
38     {
39         // Sanity check first
40         assertEquals(locale, mapper.getDeserializationConfig().getLocale());
41 
42         final String ORIGINAL_KEY = "someId";
43 
44         Id953 result;
45         result = mapper.readValue("{\""+ORIGINAL_KEY+"\":1}", Id953.class);
46         assertEquals(1, result.someId);
47 
48         result = mapper.readValue("{\""+ORIGINAL_KEY.toUpperCase(locale)+"\":1}", Id953.class);
49         assertEquals(1, result.someId);
50 
51         result = mapper.readValue("{\""+ORIGINAL_KEY.toLowerCase(locale)+"\":1}", Id953.class);
52         assertEquals(1, result.someId);
53 
54         // and finally round-trip too...
55         final Id953 input = new Id953();
56         input.someId = 1;
57         final String json = mapper.writeValueAsString(input);
58 
59         result = mapper.readValue(json, Id953.class);
60         assertEquals(1, result.someId);
61     }
62 }
63