How Deserialization Yaml Array to List<ParserRule> type

Issue #388 duplicate
Zixuan Liu created an issue

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)

  1. Zixuan Liu reporter

    thanks,I have solved the problem,I feel better like gson lib deserialize yaml array to list.

  2. Log in to comment