Skip to content

Serializing and Deserializing Locale.ROOT #1123

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
hookumsnivy opened this issue Feb 8, 2016 · 5 comments
Closed

Serializing and Deserializing Locale.ROOT #1123

hookumsnivy opened this issue Feb 8, 2016 · 5 comments
Milestone

Comments

@hookumsnivy
Copy link

Serializing and Deserializing Locale objects seems to work just fine, until you try on the Root Locale.
It writes it out as an empty string and when it reads it in, the value is null

@Test
    public void testLocaleDeserialization() throws IOException {
        ObjectMapper objectMapper = new ObjectMapper();
        Locale root = Locale.ROOT;
        String json = objectMapper.writeValueAsString(root);
        System.out.printf("Root Locale: '%s'", json);
        Locale actual = objectMapper.readValue(json, Locale.class);
        Assert.assertEquals(root, actual);
    }

Here is the output:
Root Locale: '""'
java.lang.AssertionError:
Expected :
Actual :null

@hookumsnivy
Copy link
Author

This might not be backwards compatible, but in Java 7+ you can use Locale.forLanguageTag(String) to deserialize and Locale.toLanguageTag() to serialize.
For the time being I've added a custom serializer and deserializer that does exactly that.

@cowtowncoder
Copy link
Member

@hookumsnivy thank you for reporting this & for the suggestion of fix. I'll have to think about the solution; my main concern is just that while we are moving to require JDK7 baseline, there is bit of transition where we try to keep runtime JDK6 compatible. But adding special handling for "" seems simple enough even using a work-around.

@hookumsnivy
Copy link
Author

@cowtowncoder It looks like FromStringDeserializer already has special handling for "" in the case of URIs.

@cowtowncoder
Copy link
Member

@hookumsnivy right, that's not a problem from my perspective, can add it once I have time to work on this.

@cowtowncoder
Copy link
Member

Ok... so the problem really is the special handling for empty String. Gotcha.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants