Serializing List of Specific Objects

53 views
Skip to first unread message

haja gecko

unread,
Apr 26, 2017, 2:47:18 AM4/26/17
to yamlbeans-users
Hi, I'm trying to deserialize the following parameter file: 
The structure of the file is repetitive and I would like List<SystemParameter> 

parameter: refresh-token
category: System Parameter
defaultValue: 1
cache: false
envs:
- env: local
value: 1
- env: dev
value: 1
- env: prod
value: 1
parameter: token2
category: System Parameter
defaultValue: 1
cache: false
envs:
- env: local
value: 1
- env: dev
value: 1
- env: prod
value: 1


Here is my POJO:

public class SystemParameter {
private String parameter;
private String category;
private String defaultValue;
private String cache;
private List<EnvironmentValue> envs;
...
}
Here is my main: 

public class SystemParameterReader {
public static void main (String[] args) throws Exception {
String systemParameterFile = "systemParameter.yaml";
URL configUrl = ClassLoader.getSystemResource (systemParameterFile);
String fileName = configUrl.getFile();
YamlReader yamlReader = new YamlReader (new FileReader (fileName));
SystemParameter all = yamlReader.read(SystemParameter.class, List.class);

//for(Object sys : all) {
//SystemParameter s = (SystemParameter) sys;
System.out.println (all);
//}
}
}

As I mention above, I would like the YamlReader.read (...) to return me a List<SystemParameter>, 
in this case, 2 items in the list, 1) refresh-token, 2) token2.

I've tried 
1)
   SystemParameter all = yamlReader.read(SystemParameter.class, List.class);
But this only returns the last SystemParameter token2, and not a list of SystemParameter as I had expected

2)
   List all = yamlReader.read(List.class, SystemParameter.class);
errors with Line 1, column 10: Unable to find property 'parameter' on class: java.util.List

Not sure how to do what I want. I'm using 1.11, and assuming it can do what I'm asking it to do.

Any help ...

Reply all
Reply to author
Forward
0 new messages