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

Reopen: YAML Anchor, reference fails with simple example #123 #296

Open
vitaliy-sk opened this issue Dec 9, 2021 · 0 comments
Open

Reopen: YAML Anchor, reference fails with simple example #123 #296

vitaliy-sk opened this issue Dec 9, 2021 · 0 comments

Comments

@vitaliy-sk
Copy link

Issue #123 reproducible on 2.13.0

Code sample:

package test;

import com.fasterxml.jackson.annotation.JsonIdentityInfo;
import com.fasterxml.jackson.annotation.ObjectIdGenerators;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.dataformat.yaml.YAMLFactory;

public class Test {

    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";
        System.out.println(YAML_CONTENT);
        System.out.println("---");
        ObjectMapper om = new ObjectMapper(new YAMLFactory());
        ScratchModel result = om.readValue(YAML_CONTENT, ScratchModel.class);
        System.out.println(result);
    }

    public static void main(String[] args) throws Exception {
        new Test().testObjectIdUsingNative();
    }

}

Output:

foo: &foo1
  value: bar
boo: *foo1

---
Exception in thread "main" com.fasterxml.jackson.databind.exc.MismatchedInputException: Cannot construct instance of `test.Test$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: test.Test$ScratchModel["boo"])
	at com.fasterxml.jackson.databind.exc.MismatchedInputException.from(MismatchedInputException.java:63)
	at com.fasterxml.jackson.databind.DeserializationContext.reportInputMismatch(DeserializationContext.java:1588)
	at com.fasterxml.jackson.databind.DeserializationContext.handleMissingInstantiator(DeserializationContext.java:1213)
	at com.fasterxml.jackson.databind.deser.std.StdDeserializer._deserializeFromString(StdDeserializer.java:311)
	at com.fasterxml.jackson.databind.deser.BeanDeserializerBase.deserializeFromString(BeanDeserializerBase.java:1495)
	at com.fasterxml.jackson.databind.deser.BeanDeserializer._deserializeOther(BeanDeserializer.java:207)
	at com.fasterxml.jackson.databind.deser.BeanDeserializer.deserialize(BeanDeserializer.java:197)
	at com.fasterxml.jackson.databind.deser.impl.FieldProperty.deserializeAndSet(FieldProperty.java:138)
	at com.fasterxml.jackson.databind.deser.BeanDeserializer.vanillaDeserialize(BeanDeserializer.java:324)
	at com.fasterxml.jackson.databind.deser.BeanDeserializer.deserialize(BeanDeserializer.java:187)
	at com.fasterxml.jackson.databind.deser.DefaultDeserializationContext.readRootValue(DefaultDeserializationContext.java:322)
	at com.fasterxml.jackson.databind.ObjectMapper._readMapAndClose(ObjectMapper.java:4593)
	at com.fasterxml.jackson.databind.ObjectMapper.readValue(ObjectMapper.java:3548)
	at com.fasterxml.jackson.databind.ObjectMapper.readValue(ObjectMapper.java:3516)
	at test.Test.testObjectIdUsingNative(Test.java:34)
	at test.Test.main(Test.java:39)
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

2 participants