【发布时间】:2013-08-27 02:08:05
【问题描述】:
我正在考虑使用带有 SnakeYAML 的自定义构造,但不确定如何实现嵌套。我使用this example 作为参考。
在链接的例子中,相关的 YAML 和 Construct 是,
- !circle
center: {x: 73, y: 129}
radius: 7
private class ConstructCircle extends AbstractConstruct {
@SuppressWarnings("unchecked")
public Object construct(Node node) {
MappingNode mnode = (MappingNode) node;
Map<Object, Object> values = constructMapping(mnode);
Circle circle = new Circle((Map<String, Integer>) values.get("center"), (Integer) values.get("radius"));
return circle;
}
}
现在,让我们将 YAML 更改为,
- !circle
center: !point
x: 73
y: 129
radius: 7
我想使用另一个AbstractConstruct 来解析该!point 对象,但在ConstructCircle 上下文中进行。我对Construct/Node 关系的理解非常不稳定,我不知道如何在自定义构造函数中使用自定义构造函数。有什么想法或资源吗?
【问题讨论】: