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

BeanDeserializerModifier.modifyDeserializer() not applied to custom bean deserializers #2392

Closed
andreasbaus opened this issue Jul 26, 2019 · 2 comments
Milestone

Comments

@andreasbaus
Copy link

andreasbaus commented Jul 26, 2019

When trying to modify the default deserializer for java.time.Instant using a BeanDeserializerModifier, I noticed that the modifier is not actually applied. On the other hand, a BeanSerializerModifier works just fine.

The issue seems to be the following: in com.fasterxml.jackson.databind.ser.BeanSerializerFactory, method _createSerializer2 first looks for a custom serializer, stores it in a local variable ser:

                // Modules may provide serializers of POJO types:
                for (Serializers serializers : customSerializers()) {
                    ser = serializers.findSerializer(config, type, beanDesc);
                    if (ser != null) {
                        break;
                    }
                }

and at the end tries looking for matching modifiers and applies them if available, before returning ser:

        if (ser != null) {
            // [databind#120]: Allow post-processing
            if (_factoryConfig.hasSerializerModifiers()) {
                for (BeanSerializerModifier mod : _factoryConfig.serializerModifiers()) {
                    ser = mod.modifySerializer(config, beanDesc, ser);
                }
            }
        }
        return ser;

The BeanDeserializerFactory on the other hand just looks for a custom deserializer, and if found, returns it immediately:

        JsonDeserializer<Object> custom = _findCustomBeanDeserializer(type, config, beanDesc);
        if (custom != null) {
            return custom;
        }

without passing throug the logic handling deserializer modifiers - this only happens in the method findStdDeserializer, which would be called further down but only if none of the early returns before its invocation happen.

Shouldn't a deserializer modifier have a chance to be applied to a custom deserializer as well, just like a serializer modifier already is to a custom serializer? The way it currently is handled is kind of inconsistent.

Affected version: 2.9.9.1

(The reason that there is a custom serializer and deserializer registered for java.time.Instant by the way is that it comes from com.fasterxml.jackson.datatype.jsr310.JavaTimeModule.)

@cowtowncoder
Copy link
Member

Hmmh. Good question... I would think that, yes, custom deserializers should also go through same process.

Timing for fixing this (assuming I can reproduce it) is good as it could go in 2.10: I'd be bit hesitant to do this in a patch.

@cowtowncoder
Copy link
Member

Actually, looks like every other kind of custom deserializer has already been subject to modification and literally the only case this was missing is the custom "bean" deserializer.
So adding makes sense.

@cowtowncoder cowtowncoder added this to the 2.10.0.pr2 milestone Aug 1, 2019
@cowtowncoder cowtowncoder changed the title BeanDeserializerModifier not applied to custom bean deserializers BeanDeserializerModifier.modifyDeserializer() not applied to custom bean deserializers Aug 1, 2019
cowtowncoder added a commit that referenced this issue Aug 1, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants