Skip to content

Enum values can not be read from single-element array even with DeserializationFeature.UNWRAP_SINGLE_VALUE_ARRAYS #3655

@AndrejMitrovic

Description

@AndrejMitrovic

Using Jackson 2.9.9.3.

This issue was carried over from micronaut-core: micronaut-projects/micronaut-core#8215

Example test-case:

package arrayissue;

import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.DeserializationFeature;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.annotation.JsonCreator;

enum MyEnum {
    FOO("FOO"),
    BAR("BAR");

    private String value;

    MyEnum(String value) {
        this.value = value;
    }

    public static void main(String[] args) throws JsonProcessingException {
        ObjectMapper om = new ObjectMapper();
        om.enable(DeserializationFeature.UNWRAP_SINGLE_VALUE_ARRAYS);
        System.out.println(om.readValue("\"FOO\"", MyEnum.class));
        System.out.println(om.readValue("[\"FOO\"]", MyEnum.class));
    }

    @JsonCreator
    public static MyEnum fromValue(String text) {
        System.out.println("-- CONVERTING FROM: " + text);
        return MyEnum.FOO;
    }
}

Result:

-- CONVERTING FROM: FOO
FOO
-- CONVERTING FROM: null
FOO

Metadata

Metadata

Assignees

No one assigned

    Labels

    enumRelated to handling of Enum values

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions