Skip to content

Accept lowerCase enums for Range BoundType serialization #102

@turbospaces

Description

@turbospaces

This code doesn't work as expected

String json = "{\"lowerEndpoint\":1,\"lowerBoundType\":\"closed\",\"upperEndpoint\":2,\"upperBoundType\":\"closed\"}";
Range range = new ObjectMapper()
.enable(MapperFeature.ACCEPT_CASE_INSENSITIVE_ENUMS)
.enable(MapperFeature.ACCEPT_CASE_INSENSITIVE_PROPERTIES)
.enable(MapperFeature.ACCEPT_CASE_INSENSITIVE_VALUES)
.readValue(json, Range.class);

This is because valueOf is being used, however it breaks concept of accepting case-insensitive enums above

private BoundType deserializeBoundType(DeserializationContext context, JsonParser p) throws IOException
    {
        expect(context, JsonToken.VALUE_STRING, p.getCurrentToken());
        String name = p.getText();
        try {
            return BoundType.valueOf(name);
        } catch (IllegalArgumentException e) {
            return (BoundType) context.handleWeirdStringValue(BoundType.class, name,
                    "not a valid BoundType name (should be one oF: %s)",
                    Arrays.asList(BoundType.values()));
        }
    }

Fix is dead straightforward IMHO

Metadata

Metadata

Assignees

No one assigned

    Labels

    good first issueIssue that seems easy to resolve and is likely a good candidate for contributors new to projectguava

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions