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

Accept lowerCase enums for Range BoundType serialization #102

Closed
turbospaces opened this issue Feb 3, 2023 · 3 comments · Fixed by #108
Closed

Accept lowerCase enums for Range BoundType serialization #102

turbospaces opened this issue Feb 3, 2023 · 3 comments · Fixed by #108
Labels
good first issue Issue that seems easy to resolve and is likely a good candidate for contributors new to project guava
Milestone

Comments

@turbospaces
Copy link

turbospaces commented Feb 3, 2023

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

@cowtowncoder
Copy link
Member

If fix is dead straight-forward, a PR would be most appreciated!

@cowtowncoder cowtowncoder added the good first issue Issue that seems easy to resolve and is likely a good candidate for contributors new to project label Mar 6, 2023
@cowtowncoder
Copy link
Member

@JooHyukKim another issue that might interest you.

@JooHyukKim
Copy link
Member

@cowtowncoder 🙏🏼 thankssss.
I will look it.

@cowtowncoder cowtowncoder changed the title guava Range BoundType serialization (accept lowerCase enums) accept lowerCase enums for Range BoundType serialization Mar 7, 2023
@cowtowncoder cowtowncoder added this to the 2.15.0 milestone Mar 7, 2023
@cowtowncoder cowtowncoder changed the title accept lowerCase enums for Range BoundType serialization Accept lowerCase enums for Range BoundType serialization Dec 12, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
good first issue Issue that seems easy to resolve and is likely a good candidate for contributors new to project guava
Projects
None yet
3 participants