- changed status to duplicate
How Deserialization Yaml Array to List<ParserRule> type
Issue #388
duplicate
JavaBean
@Data
public class ParserRule {
private String bankName;
private String bankCode;
}
Yaml
- bankName: Test1
bankCode: CMB
- bankName: Test2
bankCode: BOC
main.java
Yaml yaml = new Yaml();
List<ParserRule> lists = (List<ParserRule>)yaml.load(body);
System.out.println(lists); // this is ok
for(ParserRule list : lists){
System.out.println(list.getBankcode()); // this is error
}
Exception in thread "main" java.lang.ClassCastException: java.util.LinkedHashMap cannot be cast to com.nodece.ParserRule
i need your help, thanks
Comments (3)
-
-
ATM, I don't see how you can do it without explicit tags for ParseRule.
Or if you put that list as property of some JavaBean it may work.
@Data public class RulesContainer { private List<ParseRule> rules; }
BTW, this is wrong place to ask question. Especially starting "How ...."
Try https://groups.google.com/forum/#!forum/snakeyaml-core first.
-
reporter thanks,I have solved the problem,I feel better like gson lib deserialize yaml array to list.
- Log in to comment
Duplicate of #387.