Closed micsport13 closed 9 months ago
I think there is a YAMLGenerator.Feature
that controls whether "native" Type Id is used. I forget its name (let me know if you can't find it), and I think it is enabled by default. If so, it uses YAML's type id ("tag") to include id to be more YAML-like. If you disable that Feature, it'll instead use generic, JSON like Type Id.
Ah perfect. The relevant setting was to disable USE_NATIVE_TYPE_ID. What is the purpose of these type ids?
@micsport13 It is just "natural" thing to use for YAML: JSON does not have any special marker for type ids so it must use a regular property (or one of altenratives, wrapper Array or wrapper Object). But since YAML has, and many YAML tools expect tags, Jackson can also produce those (as well as read).
Or, if you prefer, cross-format alternatives that JSON uses.
So it's all for YAML compatibility.
There's equivalent thing for Object Ids ("anchors" in YAML) wrt @JsonIdentityInfo
ids.
I hope this helps!
Thanks for the help! I'll have to look into this more because maybe that's better long term for my project.
I'm pretty new to Jackson so forgive me if this is a simple question or configuration that I'm just missing, but I'm trying to serialize a set of classes that implement an interface. When I use the default YAMLMapper , I get an output for one of the keys as
!<TypeName> {}
, yet when I use the JsonMapper, the output comes out as expected where it outputs something likeYaml outputs as
This is the main class:
DataType class
One subtype class
Object Mapper usage
When I use
new JsonMapper()
instead of YamlMapper, I get the desired output. Is there something I'm doing wrong here?