Skip to content

DeserializationFeature.UNWRAP_SINGLE_VALUE_ARRAYS don't support Map type field #2767

@abomb4

Description

@abomb4

I have a simple test code:

@Data
public class The {
    private String the;
    private Map<String, Integer> the2;
    private The the3;

    public static void main(String[] args) throws Exception {
        final ObjectMapper mapper = new ObjectMapper();
        mapper.enable(DeserializationFeature.UNWRAP_SINGLE_VALUE_ARRAYS);
        // Cannot deserialize instance of `java.util.LinkedHashMap<java.lang.Object,java.lang.Object>` out of START_ARRAY token
        // final String json = "{\"the\":[\"a\"],\"the2\":[{\"a\":1,\"b\":2}],\"the3\":[{\"the\":\"aaa\"}]}";
        final String json = "{\"the\":[\"a\"],\"the2\":{\"a\":1,\"b\":2},\"the3\":[{\"the\":\"aaa\"}]}";
        System.out.println(json);
        final The v = mapper.readValue(json, The.class);

        System.out.println(mapper.writeValueAsString(v));
    }
}

Using the first json will cause com.fasterxml.jackson.databind.exc.MismatchedInputException, but using the next json has no problem.
It seems that DeserializationFeature.UNWRAP_SINGLE_VALUE_ARRAYS doesn't support a Map type field. Is this a bug?

My jackson-databind version: 2.10.4

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions