Java 使用FasterXML解析带别名的yml文件
我有一个包含多个对象的yaml文件和一个使用yaml v1.2规范中的锚/别名(&/*)的列表:Java 使用FasterXML解析带别名的yml文件,java,yaml,fasterxml,aliases,Java,Yaml,Fasterxml,Aliases,我有一个包含多个对象的yaml文件和一个使用yaml v1.2规范中的锚/别名(&/*)的列表: key1: subkey: &myalias - attr1: valueX attr2: valueY attr3: valueZ - attr1: another_valueX attr2: another_valueY attr3: another_valueZ key2: subkey: *myalias 我有
key1:
subkey: &myalias
- attr1: valueX
attr2: valueY
attr3: valueZ
- attr1: another_valueX
attr2: another_valueY
attr3: another_valueZ
key2:
subkey: *myalias
我有以下Java类:
package com.acme.model;
import lombok.Data;
import java.io.Serializable;
@Data
public class FileObject implements Serializable {
private KeyObject key1;
private KeyObject key2;
public FileObject() {}
}
---
package com.acme.model;
import lombok.Data;
import java.io.Serializable;
@Data
public class KeyObject implements Serializable {
private SubkeyList subkey;
public KeyObject() {}
}
---
package com.acme.model;
import com.fasterxml.jackson.annotation.JsonIdentityInfo;
import com.fasterxml.jackson.annotation.ObjectIdGenerators;
import lombok.Data;
import java.io.Serializable;
import java.util.ArrayList;
@Data
@JsonIdentityInfo(generator = ObjectIdGenerators.PropertyGenerator.class, property = "subkeyId")
public class SubkeyList extends ArrayList<SubkeyObject> implements Serializable {
private String subkeyId;
public SubkeyList() {}
}
---
package com.acme.model;
import lombok.Data;
import java.io.Serializable;
@Data
public class SubkeyObject implements Serializable {
private String attr1;
private String attr2;
private String attr3;
public SubkeyObject() {}
}
但出现了以下例外情况:
com.fasterxml.jackson.databind.exc.MismatchedInputException: Cannot deserialize instance of `com.acme.model.SubkeyList<com.acme.model.SubkeyObject>` out of VALUE_STRING token
at [Source: (BufferedInputStream); line: 10, column: 11] (through reference chain: com.acme.model.FileObject["key2"]->com.acme.model.KeyObject["subkey"])
com.fasterxml.jackson.databind.exc.mismatchdinputException:无法反序列化'com.acme.model.SubkeyList'的实例值不足\u字符串标记
在[Source:(BufferedInputStream);行:10,列:11](通过引用链:com.acme.model.FileObject[“key2”]->com.acme.model.KeyObject[“subkey”])
我还没有找到将别名和锚点用于列表或地图的文档,仅用于对象
com.fasterxml.jackson.databind.exc.MismatchedInputException: Cannot deserialize instance of `com.acme.model.SubkeyList<com.acme.model.SubkeyObject>` out of VALUE_STRING token
at [Source: (BufferedInputStream); line: 10, column: 11] (through reference chain: com.acme.model.FileObject["key2"]->com.acme.model.KeyObject["subkey"])