I have a YAML I am trying to create using the mustache template(s) for a state diagram. It looks like this:
states:
{{#states}}
"{{name}}":
properties:
{{#properties}}
{{key}} : "{{value}}"
options:
{{#options}}
{{value}}: {{key}}
{{/options}}
{{/properties}}
transitions:
{{#transitions}}
{{key}} : {{value}}
{{/transitions}}
{{/states}}
The structure looks somewhat like this and I am unable to create the correct POJO mapping/method to get it to work. The documentation and the 2 samples on github do not deal with this in detail.
I can print the "states" just fine and even the "properties" and "transitions" just fine from the accompanying POJOs, but I am unable to the "options" to work.
Currently I have a class, with a bunch of code, the relevant parts are copied here:
Set<Map.Entry<String,String>> properties(State state) {
Map mapOfProperties = new HashMap();
switch (state.getType()) {
case text:
mapOfProperties.put("text", state.getMessage());
break;
case list:
mapOfProperties.put("prompt", state.getMessage());
mapOfProperties.put("variable", "someAction");
// I was hoping to add something here, such that the options sub tree can be added here. Just not sure what to put?
// Something similar to the following, that would put options: one line and
// the actual key/value pairs on the next few lines, somewhat similar to
// options:
//. key1: value1
//. key2: value2
// mapOfProperties.put("options:", options(state));
break;
default:
throw new IllegalStateException("Unexpected value: " + state.getType());
}
return mapOfProperties.entrySet();
}
Code for "options" method: