Skip to content

Instantly share code, notes, and snippets.

@asafjaffi
Created November 11, 2013 14:01
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save asafjaffi/7413605 to your computer and use it in GitHub Desktop.
Save asafjaffi/7413605 to your computer and use it in GitHub Desktop.
Testing to see when the Locale deserializer works
import java.io.IOException;
import java.util.HashMap;
import java.util.Locale;
import java.util.Map;
import org.codehaus.jackson.JsonGenerationException;
import org.codehaus.jackson.map.JsonMappingException;
import org.codehaus.jackson.map.ObjectMapper;
import org.codehaus.jackson.type.TypeReference;
import org.junit.Test;
public class LocaleMappingWithJacksonTest {
@Test
public void testLocaleMapping() throws JsonGenerationException, JsonMappingException, IOException {
ObjectMapper mapper = new ObjectMapper();
Map<String, Locale> writeMap = new HashMap<String, Locale>();
writeMap.put("key", Locale.ENGLISH);
String json = mapper.writeValueAsString(writeMap);
HashMap<String, Locale> readMap = mapper.readValue(json,
new TypeReference<HashMap<String, Locale>>() {
});
assertEquals(Locale.ENGLISH, readMap.get("key"));
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment