I want to read a YAML document to a map of custom objects (instead of maps, which snakeYaml does by default). So this:
19:
typeID: 2
limit: 300
20:
typ
You need to add a custom Constructor. However, in your case you don't want register an "item" or "item-list" tag.
In effect, you want to apply Duck Typing to your Yaml. It's not super efficient, but there is a relatively easy way to do this.
class YamlConstructor extends Constructor {
@Override
protected Object constructObject(Node node) {
if (node.getTag() == Tag.MAP) {
LinkedHashMap map = (LinkedHashMap) super
.constructObject(node);
// If the map has the typeId and limit attributes
// return a new Item object using the values from the map
...
}
// In all other cases, use the default constructObject.
return super.constructObject(node);