Skip to content

Locale "" is deserialised as null if ACCEPT_EMPTY_STRING_AS_NULL_OBJECT is enabled #4009

Closed
@pkraeutli

Description

@pkraeutli

Describe the bug

When trying to deserialise an empty JSON string as java.util.Locale, the resulting value is NULL, when ACCEPT_EMPTY_STRING_AS_NULL_OBJECT is set to true.
My expectation was that the empty string would be converted to Locale.ROOT.

Version information
2.13.5

To Reproduce

The following test fails:

class JsonDeserializationTest
{
    @Test
    void testDeserializeRootLocale() throws JsonProcessingException
    {
        ObjectMapper objectMapper = new ObjectMapper();
        objectMapper.configure(DeserializationFeature.ACCEPT_EMPTY_STRING_AS_NULL_OBJECT, true);

        assertEquals(Locale.ROOT, objectMapper.readValue("\"\"", Locale.class));
    }
}

When looking at the current source code at https://github.com/FasterXML/jackson-databind/blob/2.16/src/main/java/com/fasterxml/jackson/databind/cfg/CoercionConfigs.java#L241
It looks like CoercionAction.TryConvert should be returned in this case.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions