【发布时间】:2018-03-20 11:28:20
【问题描述】:
我有如下 Yaml 文件
Network:
Input 1:
- profile : "1"
- size: 2
Input 2:
- profile : "1"
- size: 3
Input 1:
- profile :"2"
- size:100
Input 2:
- name :"N"
- source: "test"
并正在使用以下依赖项将其转换为类对象
import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.dataformat.yaml.YAMLFactory;
ObjectMapper mapper = new ObjectMapper(new YAMLFactory());
Tiles tiles = mapper.readValue(new File(args[0]), Tiles.class);
我的 Tiles 类如下所示
public class Tiles {
@JsonProperty
private Network network;
public Network getNetwork() {
return network;
}
public void setNetwork(Network network) {
this.network = network;
}
}
public class Network {
public Network() {
super();
}
@JsonProperty
private List<String> input;
public List<String> getInput() {
return input;
}
public void setInput(List<String> input) {
this.input= input;
}
但是当使用 ObjectMapper 解析 YAML 文件时,我得到一个异常,例如com.fasterxml.jackson.databind.JsonMappingException:
我想按顺序处理 YAML 文件,即使 Input 被不同的名称替换,我的意思是 我必须先输入输入 1,然后输入输入 2,然后以此类推
感谢任何帮助。
提前致谢
【问题讨论】: