我正在尝试将 YAML 文件解析为对象。
尽管 Online YAML 解析器告诉我它可以按照我想要的方式进行解析,但 Jackson YAML 解析器拒绝给我我想要的东西。
这是 YAML 文件:
- nom: "service1"
etats : &e1s1
- nom: "e1"
childs:
- nom: "e2"
childs:
- nom: "e3"
childs:
- &a
nom: "e5"
- nom: "e4"
childs:
- <<: *a
在线 YAML 解析器告诉我“e4”和“e3”有“e5”作为子项。
但是,当我尝试用 Jackson 解析它时,出现以下错误:
com.fasterxml.jackson.databind.exc.UnrecognizedPropertyException: Unrecognized field "<<" (class Etat), not marked as ignorable (4 known properties: "dependsOnAnotherService", "nom", "hasToken", "childs"])
at [Source: (File); line: 13, column: 21] (through reference chain: java.lang.Object[][0]->Service["etats"]->java.util.ArrayList[0]->Etat["childs"]->java.util.ArrayList[1]->Etat["childs"]->java.util.ArrayList[0]->Etat["<<"])
所以,我想知道是否有人有办法做到这一点,杰克逊会接受?
Update
我也尝试过这个:
- nom: "service1"
etats : &e1s1
- nom: "e1"
childs:
- nom: "e2"
childs:
- nom: "e3"
childs:
- &a
nom: "e5"
- nom: "e4"
childs:
- *a
但得到:
com.fasterxml.jackson.databind.exc.MismatchedInputException: Cannot construct instance of `Etat` (although at least one Creator exists): no String-argument constructor/factory method to deserialize from String value ('a')
at [Source: (File); line: 13, column: 15] (through reference chain: java.lang.Object[][0]->Service["etats"]->java.util.ArrayList[0]->Etat["childs"]->java.util.ArrayList[1]->Etat["childs"]->java.util.ArrayList[0])