I'm currently trying to parse a YAML file as input/configuration for running some tests. The problem is: using Jackson, nesting data seems not to fit within the class regardless of the structure i design for it, almost every time I'm getting something like this:
com.fasterxml.jackson.databind.exc.MismatchedInputException: Cannot deserialize instance of `java.util.ArrayList` out of START_OBJECT token
I intent to simply "search" for the data within the YAML file using a similar approach of the XPath, without worrying about mapping objects and finite levels of nesting.
Here is the example class:
public class YAMLInput {
private ArrayList<SomeContainer> containers;
//getter and setters
private class SomeContainer {
private String name;
private String path;
private ArrayList<Integer> intList;
private ArrayList<String> strList;
private ArrayList<SomeObject> someObjList;
private class SomeObject {
private String objectName;
private ArrayList<String> strList;
}
}
}
And the Yaml input:
container:
name: Cont1
path: /storage/outputFolder
intList:
- 100
- 200
- 300
strList:
- strFirst
- strSecond
- strThird
someObjList:
obj1:
objName: strname
strList:
- 100
- 200
- 300
obj2:
# (...)
The idea is to build a constructor for the YAMLInput
class:
public YAMLInput( SearchableYAMLData data) {
for(SearchableYAMLData container : data.getList("container")){
this.containers.add( new SomeContainer());
this.containers.get(0) = container.get("name");
//...
}
}
What would be the closest available tool to this hypothetical SearchableYAMLData
class?