问题描述
我有一个包含多个对象的 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
我有以下 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() {}
}
ObjectReader reader = new ObjectMapper(new YAMLFactory()).readerFor(FileObject.class);
InputStream in = this.getClass().getClassLoader().getResourceAsstream("file.yml");
FileObject fileObject = reader.readValue(in);
但是出现以下异常:
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"])
我没有找到将别名和锚点用于列表或地图的文档,仅用于对象。
解决方法
暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!
如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。
小编邮箱:dio#foxmail.com (将#修改为@)