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) Support anchors for simple-scalar values #6

Open
cowtowncoder opened this issue Mar 19, 2017 · 1 comment
Open

(yaml) Support anchors for simple-scalar values #6

cowtowncoder opened this issue Mar 19, 2017 · 1 comment
Labels
yaml Issue related to YAML format backend

Comments

@cowtowncoder
Copy link
Member

(note: based on https://github.com/FasterXML/jackson-dataformat-yaml/issues/62)

If possible, it would be great to be able to support anchors for simple scalar values.

The original test case to show this would be:

public class YamlParserTest {
    private ObjectMapper objectMapper = new ObjectMapper(new YAMLFactory());

    public static class Test1 {
        public Long value1;
        public Long value2;
    }

    @Test
    public void test() throws IOException {
        String yaml =
        "value1: &test_1 123\n" +
        "value2: *test_1";
        Test1 test1 = objectMapper.readValue(yaml, Test1.class);
        assertEquals(123L, test1.getValue1().longValue());
        assertEquals(123L, test1.getValue2().longValue());
    }
}
@cowtowncoder
Copy link
Member Author

Note that the original test case does not and will not work -- Jackson requires definition of values that are referenceable, regardless of underlying data format.
This is done by using annotation

@JsonIdentityInfo

on type or property. Further, type to annotate needs to be POJO type (or, property value needs to be POJO type when used on properties).

But with these modifications, perhaps it should be possible to define POJO type that serializes as an integer number, and then use Object Id references?
This is challenging since representation in such cases is similar (by shape, that is, scalar datatype), and may not be something that can be supported. But this is not yet known to be a hard limitation.

@cowtowncoder cowtowncoder added the yaml Issue related to YAML format backend label Mar 20, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
yaml Issue related to YAML format backend
Projects
None yet
Development

No branches or pull requests

1 participant