0

I have a Yaml file that's something like below:

rules:
  - p_table: 
        ["p_event/Name", 
         "p_fault/Name"]
  - s_table: 
        ["s_event/Name", 
         "s_fault/Name"]
  - r_table: 
        ["r_event/Name", 
         "r_fault/Name"]

So, I can already take the .yml file above and parse through it with YamlBeans and print it out with code like below:

System.out.println(map.get("rules"));

This gives this kind of result:

[{p_table=[p_event/Name, p_fault/Name]}, 
{s_table=[s_event/Name, s_fault/Name]}, 
{r_table=[r_event/Name, r_fault/Name]}]

What I would like to do is more on this sort of level, where I can store it in a HashMap and actually use the specifics within the map, with something like this:

HashMap<String, ArrayList<Strings>> Policies = (HashMap)(map.get("rules"));

But when I do that I either have an exception thrown or it just returns null, is there a solution for this should I not be using HashMaps... or can I just not translate objects in such a way? I plan on replacing the String with another type from a different library that uses Strings but wanted to start at the bottom and then go up from there.

veila
  • 83
  • 8

1 Answers1

0

The obvious solution would be to remove the sequence from the YAML file:

rules:
  p_table: 
    ["p_event/Name", 
     "p_fault/Name"]
  s_table: 
    ["s_event/Name", 
     "s_fault/Name"]
  r_table: 
    ["r_event/Name", 
     "r_fault/Name"]

If you can't change the YAML file, you need to transform the data after loading it.

flyx
  • 35,506
  • 7
  • 89
  • 126