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

YAML Anchor, reference fails with simple example #123

Closed
cowtowncoder opened this issue Feb 19, 2019 · 2 comments
Closed

YAML Anchor, reference fails with simple example #123

cowtowncoder opened this issue Feb 19, 2019 · 2 comments
Milestone

Comments

@cowtowncoder
Copy link
Member

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"])
...
@cowtowncoder
Copy link
Member Author

It's odd this does not work, considering there is a basic test for native object ids (anchors), references working. Need to figure out what is the difference...

@cowtowncoder
Copy link
Member Author

Ok, interesting. It looks like aggressive clearing of anchor value in YAMLParser.nextToken() causes the problem somehow.

I think what basically happens is that there are 2 potential YAML locations -- before logical start of Object, and for the first key/value pair -- that sort of conflict in that only second will be retained. So need to figure out how to retain first value.

@cowtowncoder cowtowncoder added 2.9 and removed 2.10 labels Feb 21, 2019
@cowtowncoder cowtowncoder added this to the 2.9.9 milestone Feb 21, 2019
pjankovsky pushed a commit to fivetran/jackson-dataformats-text that referenced this issue Jun 25, 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

1 participant