Skip to content

StdValueInstantiator.withArgsCreator is now set for creators with no argumentsΒ #4777

@k163377

Description

@k163377

Search before asking

  • I searched in the issues and found nothing similar.

Describe the bug

This changes the behavior of StdValueInstantiator when deserializing, resulting in the following problem in kotlin-module.
FasterXML/jackson-module-kotlin#841

From @JooHyukKim 's research, this has changed the result of the _vanillaProcessing determination.
FasterXML/jackson-module-kotlin#841 (comment)

I have confirmed that this value is populated by StdValueInstantiator.configurationFromObjectSettings, but have not been able to do a deeper analysis.

Version Information

2.18

Reproduction

The following code succeeds in 2.17 but fails in 2.18.

import com.fasterxml.jackson.annotation.JsonCreator;
import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.deser.ValueInstantiator;
import com.fasterxml.jackson.databind.deser.ValueInstantiators;
import com.fasterxml.jackson.databind.deser.std.StdValueInstantiator;
import com.fasterxml.jackson.databind.module.SimpleModule;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.Test;

public class Kotlin841Sample {
    static class Foo {
        @JsonCreator
        static Foo create() { return new Foo(); }
    }

    static class Instantiator extends StdValueInstantiator {
        public Instantiator(StdValueInstantiator src) {
            super(src);
        }
    }

    static class Instantiators implements ValueInstantiators {
        Instantiator last = null;

        @Override
        public ValueInstantiator findValueInstantiator(
                DeserializationConfig config,
                BeanDescription beanDesc,
                ValueInstantiator defaultInstantiator
        ) {
            if (defaultInstantiator instanceof StdValueInstantiator) {
                Instantiator instantiator = new Instantiator((StdValueInstantiator) defaultInstantiator);
                last = instantiator;
                return instantiator;
            } else {
                return defaultInstantiator;
            }
        }
    }

    @Test
    public void test() throws Exception {
        Instantiators i = new Instantiators();

        SimpleModule sm = new SimpleModule() {
            @Override
            public void setupModule(SetupContext context) {
                super.setupModule(context);
                context.addValueInstantiators(i);
            }
        };
        ObjectMapper mapper = JsonMapper.builder().addModule(sm).build();

        mapper.readValue("{}", Foo.class);

        Assertions.assertNull(i.last.getWithArgsCreator());
    }
}

Expected behavior

It must be the same as in 2.17.

Additional context

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    2.18Issues planned at 2.18 or later

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions