Hey guys, I soon plan to add YAML to my plugins and I've run into a problem I can't figure. Here's my YAML file: Code: name: MyName type: 5 codes: - name: Person1 code: 555 I can get name and type perfectly fine, but when it comes to getting information from codes it doesn't seem to work out too well. Here's my code: Code: import org.yaml.snakeyaml.*; import java.io.*; import java.util.Map; public class YamlTesting { public static void main(String[] args){ runMe(); } public static void runMe(){ Yaml yaml = new Yaml(); Reader reader = null; try{ reader = new FileReader("foo.yml"); } catch(FileNotFoundException fnfe){ System.out.println("Error!"); } Map<String, Map<String, Map<String, Object>>> data = (Map<String, Map<String, Map<String, Object>>>) yaml.load(reader); System.out.println(data.get("codes").get("name")); } } Any suggestions?
Try using the yml like this: Code: name: MyName type: 5 codes: | name: Person1 code: 555 and I think you have one extra Map no ? I can only see 2 trees the one with name types and codes, and the sub-tree of codes: Code: Map<String, Map<String, Object>>> data = ( Map<String, Map<String, Object>>>) yaml.load(reader);
Just tried your suggestions, Sammy and I'm getting this error. Which is the exact same error I was getting before. Code: Exception in thread "main" java.lang.ClassCastException: java.util.ArrayList cannot be cast to java.util.Map at YamlTesting.runMe(YamlTesting.java:25) at YamlTesting.main(YamlTesting.java:11)