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

Unable to override DeserializationFeature.READ_UNKNOWN_ENUM_VALUES_USING_DEFAULT_VALUE with JsonFormat.Feature.READ_UNKNOWN_ENUM_VALUES_USING_DEFAULT_VALUE #4489

Closed
1 task done
JooHyukKim opened this issue Apr 20, 2024 · 0 comments
Labels
2.17 Issues planned at earliest for 2.17
Milestone

Comments

@JooHyukKim
Copy link
Member

JooHyukKim commented Apr 20, 2024

Search before asking

  • I searched in the issues and found nothing similar.

Describe the bug

After #4481, I checked if we have anything else in EnumDeserializer that won't override.
READ_UNKNOWN_ENUM_VALUES_USING_DEFAULT_VALUE config does not work also.

Version Information

2.17.0

Reproduction

(Copied from my PR)

    enum Types {
        @JsonEnumDefaultValue
        DEFAULT_TYPE,
        FAST, SLOW
    }

    static class SpeedWithoutDefaultOverride {
        @JsonFormat(without = JsonFormat.Feature.READ_UNKNOWN_ENUM_VALUES_USING_DEFAULT_VALUE)
        public Types type;
    }

    static class SpeedWithDefaultOverride {
        @JsonFormat(with = JsonFormat.Feature.READ_UNKNOWN_ENUM_VALUES_USING_DEFAULT_VALUE)
        public Types type;
    }

    @Test
    public void testJsonEnumDefaultValueOverrideOverGlobalConfig() throws Exception {
        final String UNKNOWN_JSON = a2q("{'type':'OOPS!'}");

        // First, global configuration is ENABLED and JsonFeature configuration is DISABLED
        // So the test should fail
        try {
            JsonMapper.builder()
                .enable(DeserializationFeature.READ_UNKNOWN_ENUM_VALUES_USING_DEFAULT_VALUE)
                .build()
                .readValue(UNKNOWN_JSON, SpeedWithoutDefaultOverride.class);
            fail();
        } catch (InvalidFormatException e) {
            verifyException(e, "Cannot deserialize value of type");
            verifyException(e, "not one of the values accepted for Enum class");
        }

        // Second, global configuration is DISABLED and JsonFeature configuration is ENABLED
        // So the test should pass
        SpeedWithDefaultOverride pojo = JsonMapper.builder()
            .disable(DeserializationFeature.READ_UNKNOWN_ENUM_VALUES_USING_DEFAULT_VALUE)
            .build()
            .readValue(UNKNOWN_JSON, SpeedWithDefaultOverride.class);

        assertEquals(Types.DEFAULT_TYPE, pojo.type);
    }

Expected behavior

Be able to override DeserializationFeature.READ_UNKNOWN_ENUM_VALUES_USING_DEFAULT_VALUE with JsonFormat.Feature.READ_UNKNOWN_ENUM_VALUES_USING_DEFAULT_VALUE

Additional context

Filed a PR to fix this issue.

@JooHyukKim JooHyukKim added the to-evaluate Issue that has been received but not yet evaluated label Apr 20, 2024
@cowtowncoder cowtowncoder added 2.17 Issues planned at earliest for 2.17 and removed to-evaluate Issue that has been received but not yet evaluated labels Apr 20, 2024
@cowtowncoder cowtowncoder added this to the 2.17.1 milestone Apr 20, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
2.17 Issues planned at earliest for 2.17
Projects
None yet
Development

No branches or pull requests

2 participants