Skip to content
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

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

Closed
abomb4 opened this issue Jun 16, 2020 · 2 comments
Closed
Milestone

Comments

@abomb4
Copy link

abomb4 commented Jun 16, 2020

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

@abomb4 abomb4 changed the title DeserializationFeature.ACCEPT_EMPTY_ARRAY_AS_EMPTY_OBJECT don't support Map type field? DeserializationFeature.UNWRAP_SINGLE_VALUE_ARRAYS don't support Map type field? Jun 16, 2020
@cowtowncoder
Copy link
Member

Hmmh. Interesting question. I think your expectation is reasonable, so that [ ] should be coercible. So I'll consider this a bug and hope to find time to see how it can be fixed.

cowtowncoder added a commit that referenced this issue Jun 19, 2020
cowtowncoder added a commit that referenced this issue Jun 19, 2020
@cowtowncoder cowtowncoder added this to the 2.11.1 milestone Jun 19, 2020
@cowtowncoder cowtowncoder changed the title DeserializationFeature.UNWRAP_SINGLE_VALUE_ARRAYS don't support Map type field? DeserializationFeature.UNWRAP_SINGLE_VALUE_ARRAYS don't support Map type field Jun 19, 2020
@cowtowncoder
Copy link
Member

Interestingly enough, I had actually fixed this for upcoming 2.12 (as a side-effect of other refactoring). Fixed for 2.11.1.

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