Easiest way to map the field 'f' in yaml to field 'g' in the POJO

27 views
Skip to first unread message

Tim Quinn

unread,
Aug 16, 2021, 9:10:59 PM8/16/21
to SnakeYAML
Hi.

Suppose the YAML refers to several fields. All but one have the same name in the POJO class, but one field, 'f' in YAML, corresponds to 'g' in the POJO class.

What is the easiest way to tell SnakeYAML about this?

In this case, the datatype is `String` if that matters.

I tried creating a `PropertySubsitute` but that is not working. I have seen other notes about how `PropertySubstitute` needs to match the name and type, and clearly that does not apply in this use case.

I feel as if I have missed something, but I have tried what I thought would work and have not seen an example of this.

Thanks in advance.

- Tim

Tim Quinn

unread,
Aug 17, 2021, 7:33:04 PM8/17/21
to SnakeYAML

This earlier note https://groups.google.com/g/snakeyaml-core/c/c1HiLnvKv6Q/m/QHpYcg2PVDAJ describes what seems to be the right approach, at least for my situation.

We already had a custom `Constructor` and `Serializer` so I enhanced them to do the property name conversion back and forth. 

- Tim
Reply all
Reply to author
Forward
0 new messages