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

Make BeanDeserializer consider DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES to avoid buffering #3643

Open
cowtowncoder opened this issue Oct 24, 2022 · 1 comment
Labels
3.0 Issue planned for initial 3.0 release performance Issue related to performance problems or enhancements

Comments

@cowtowncoder
Copy link
Member

cowtowncoder commented Oct 24, 2022

Currently BeanDeserializer has _ignoreAllUnknown flag but it is only set if per-class annotation @JsonIgnoreProperties(ignoreUnknown = true) (or its ConfigOverride equivalent) is specified.
This flag is used to optimize handling to skip buffering for unknown properties; it would make sense to make it also consider that if DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES is disabled, property value need not be buffered.

It'd be good to test detection as well to ensure we know how settings work; perhaps by checking how BeanDeserializerBuilder works.

Note that we might want to do dynamic check for the flag, instead of modifying _ignoreAllUnknown: this because DeserializationFeatures may be changed on per-call basis (and since it can, inevitably someone will :) ).
And since the case of buffering seemingly unknown property value is presumably rare, minor overhead for feature-flag check is probably fine.

@cowtowncoder cowtowncoder added performance Issue related to performance problems or enhancements to-evaluate Issue that has been received but not yet evaluated 2.15 labels Oct 24, 2022
@cowtowncoder cowtowncoder removed the 2.15 label Jul 13, 2024
@cowtowncoder cowtowncoder added the 3.0 Issue planned for initial 3.0 release label Dec 18, 2024
@JooHyukKim
Copy link
Member

If we would do dynamic checking for the flag, BeanDeserializerBase.handleUnknownProperty() method seems to hold what we are after. Probably add the necessary config check after alongside with if ( _ignoreAllUnknown)?

/**
     * Method called when a JSON property is encountered that has not matching
     * setter, any-setter or field, and thus cannot be assigned.
     */
    @Override
    protected void handleUnknownProperty(JsonParser p, DeserializationContext ctxt,
            Object beanOrClass, String propName)
        throws IOException
    {
        if (_ignoreAllUnknown) {
            p.skipChildren();
            return;
        }
        if (IgnorePropertiesUtil.shouldIgnore(propName, _ignorableProps, _includableProps)) {
            handleIgnoredProperty(p, ctxt, beanOrClass, propName);
        }
        // Otherwise use default handling (call handler(s); if not
        // handled, throw exception or skip depending on settings)
        super.handleUnknownProperty(p, ctxt, beanOrClass, propName);
    }

@cowtowncoder cowtowncoder removed the to-evaluate Issue that has been received but not yet evaluated label Dec 20, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
3.0 Issue planned for initial 3.0 release performance Issue related to performance problems or enhancements
Projects
None yet
Development

No branches or pull requests

2 participants