Skip to content

YAML Anchor, reference fails with simple example #123

@cowtowncoder

Description

@cowtowncoder

So, although there are cases where Anchor/Reference pairs work via Jackson @JsonIdentityInfo, looks like even simple cases sometimes fail.
For example

    static class ScratchModel {
        public StringHolder foo;
        public StringHolder boo;
    }

    @JsonIdentityInfo(generator = ObjectIdGenerators.None.class)
    static class StringHolder {
        public String value;

        @Override
        public String toString() {
            return value;
        }
    }

    public void testObjectIdUsingNative() throws Exception
    {
        final String YAML_CONTENT =
                "foo: &foo1\n" +
                "  value: bar\n" +
                "boo: *foo1\n";
        ScratchModel result = MAPPER.readValue(YAML_CONTENT, ScratchModel.class);
        assertNotNull(result);
    }

fails with

com.fasterxml.jackson.databind.exc.MismatchedInputException: Cannot construct instance of `com.fasterxml.jackson.dataformat.yaml.failing.ObjectId63Test$StringHolder` (although at least one Creator exists): no String-argument constructor/factory method to deserialize from String value ('foo1')
 at [Source: (StringReader); line: 3, column: 6] (through reference chain: com.fasterxml.jackson.dataformat.yaml.failing.ObjectId63Test$ScratchModel["boo"])
...

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions