Skip to content

Varying behavior of FAIL_ON_UNRESOLVED_OBJECT_IDS when invoking readValue() using mapper.configure()and mapper.readerFor().with() #3886

@JooHyukKim

Description

@JooHyukKim

Describe the bug
Varying behavior on DeserializationFeature .FAIL_ON_UNRESOLVED_OBJECT_IDS is observed when invoking readValue() using mapper.configure(jsonWithMissingId)and mapper.readerFor().with(jsonWithMissingId)

Version information
2.15 (default branch)

To Reproduce

I have included this in #3880

Using mapper.readerFor().with()

    public void testUnresolvableWithFeatureSymmetry() throws Exception
    {
        // specifically configured to "not" fail
        IdWrapper w = MAPPER.readerFor(IdWrapper.class)
            .without(DeserializationFeature.FAIL_ON_UNRESOLVED_OBJECT_IDS)
            .readValue(a2q("{'node':123}"));
        assertNotNull(w);
        assertNull(w.node);

        // specifically configured to fail, but doesn't
        IdWrapper w2 = MAPPER.readerFor(IdWrapper.class)
            .with(DeserializationFeature.FAIL_ON_UNRESOLVED_OBJECT_IDS)
            .readValue(a2q("{'node':123}"));
        assertNotNull(w2);
        assertNull(w2.node);
    }

Using mapper.configure()

    public void testUnresolvableConfigureFeatureSymmetry() throws Exception
    {
        // specifically configured to "not" fail
        IdWrapper w = MAPPER
            .configure(DeserializationFeature.FAIL_ON_UNRESOLVED_OBJECT_IDS, false)
            .readValue(a2q("{'node':123}"), IdWrapper.class);
        assertNotNull(w);
        assertNull(w.node);

        // specifically configured to fail
        try {
            IdWrapper w2 = MAPPER
                .configure(DeserializationFeature.FAIL_ON_UNRESOLVED_OBJECT_IDS, true)
                .readValue(a2q("{'node':123}"), IdWrapper.class);
            fail("should not pass");
        } catch (UnresolvedForwardReference e) {
            verifyException(e, "Unresolved forward reference", "Object id [123]");
        }
    }

Expected behavior

Below code should fail with UnresolvedForwardReference

        // specifically configured to fail, but doesn't
        IdWrapper w2 = MAPPER.readerFor(IdWrapper.class)
            .with(DeserializationFeature.FAIL_ON_UNRESOLVED_OBJECT_IDS)
            .readValue(a2q("{'node':123}"));

Additional context
Add any other context about the problem here.

Metadata

Metadata

Assignees

No one assigned

    Labels

    to-evaluateIssue that has been received but not yet evaluated

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions