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 error when json sub types are used #25

Open
mopsop opened this issue Jul 6, 2017 · 1 comment
Open

Yaml anchor error when json sub types are used #25

mopsop opened this issue Jul 6, 2017 · 1 comment
Labels
has-failing-test Indicates that there exists a test case (under `failing/`) to reproduce the issue yaml Issue related to YAML format backend

Comments

@mopsop
Copy link

mopsop commented Jul 6, 2017

When adding Json sub types management to a class to deserialize, the references to anchors are unresolved.

The following sample is derived from ObjectIdTest.

Here is new Node class (with type attribute and JsonSubTypes annotations) :

	@JsonTypeInfo(use = JsonTypeInfo.Id.NAME, 
			include = As.PROPERTY, 
			property = "type", 
			defaultImpl = NodeWithStringId.class)
	@JsonSubTypes({ 
		@JsonSubTypes.Type(value = SubNodeWithStringId.class, name= "subnode"),
		@JsonSubTypes.Type(value = NodeWithStringId.class, name = "node") 
	})
    @JsonIdentityInfo(generator=PrefixIdGenerator.class)
    static class NodeWithStringId
    {
        public String name;
        public String type;

        public NodeWithStringId next;
        
        public NodeWithStringId() { }
        public NodeWithStringId(String name) {
            this.name = name;
        }
    }	

And a related Node subtype :

    static class SubNodeWithStringId extends NodeWithStringId
    {
    }

Now the test is :

	String yml =
	            "---\n"
                    +"&id1 name: \"first\"\n"
                    +"type: \"node\"\n"
                    +"next:\n"
                    +"  &id2 name: \"second\"\n"
                    +"  next: *id1"
	        ;


	NodeWithStringId node  = mapper.readValue(yml, NodeWithStringId.class);


        assertNotNull(node);
        assertEquals("first", node.name);
        assertNotNull(node.next);
        assertEquals("second", node.next.name);
        assertNotNull(node.next.next);
        assertSame(node, node.next.next);	

The test fails with :

com.fasterxml.jackson.databind.deser.UnresolvedForwardReference: Unresolved forward references for: 
 at [Source: java.io.StringReader@3302035b; line: 6, column: 13]Object id [id1]

If the sub type annotations are removed, the test is ok

@cowtowncoder cowtowncoder added the yaml Issue related to YAML format backend label Sep 13, 2017
@cowtowncoder cowtowncoder added need-test-case Further progress requires inclusion of problem reproduction, ideally test case and removed need-test-case Further progress requires inclusion of problem reproduction, ideally test case labels Nov 22, 2020
@cowtowncoder
Copy link
Member

Type PrefixIdGenerator missing, but was able to just use ObjectIdGenerators.StringIdGenerator instead it seems.

@cowtowncoder cowtowncoder added 2.13 has-failing-test Indicates that there exists a test case (under `failing/`) to reproduce the issue labels Nov 22, 2020
cowtowncoder added a commit that referenced this issue Nov 22, 2020
@cowtowncoder cowtowncoder removed the 2.13 label Apr 22, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
has-failing-test Indicates that there exists a test case (under `failing/`) to reproduce the issue yaml Issue related to YAML format backend
Projects
None yet
Development

No branches or pull requests

2 participants