mapping:
nature:
wetland:
buffer: [5.0]
mappings:
natural: [wetland, mud,]
meadow:
buffer: [5.0]
mappings:
landuse: [grass, meadow]
natural: [fell, grassland]
landmark:
castle:
buffer: [-5.0, 30.0, 50.0]
mappings:
bridge: [drawbridge]
historic: [castle]
public static class TagMapping {
public static class Mapping {
public List<Double> buffer;
public Map<String, List<String>> mappings;
}
public Map<String, Map<String, Mapping>> mapping;
}
package snaketest;
import java.util.List;
import java.util.Map;
import org.yaml.snakeyaml.Yaml;
import org.yaml.snakeyaml.constructor.Constructor;
public class SnakeTest {
public static class TagMapping {
public static class Mapping {
public List<Double> buffer;
public Map<String, List<String>> mappings;
}
public Map<String, Map<String, Mapping>> mapping;
}
public static TagMapping parse(String str) {
Yaml yaml = new Yaml(new Constructor(TagMapping.class));
TagMapping mapping = (TagMapping) yaml.load(str);
return mapping;
}
public static void main(String... args)
{
String testString =
"mapping:\n"+
" nature:\n"+
" wetland:\n"+
" buffer: [5.0]\n"+
" mappings:\n"+
" natural: [wetland, mud]\n"+
" meadow:\n"+
" buffer: [5.0]\n"+
" mappings:\n"+
" landuse: [grass, meadow]\n"+
" natural: [fell, grassland]\n"+
" landmark:\n"+
" castle:\n"+
" buffer: [-5.0, 30.0, 50.0]\n"+
" mappings:\n"+
" bridge: [drawbridge]\n"+
" historic: [castle]";
TagMapping m = parse(testString);
System.out.println(m.mapping.get("nature").get("wetland").mappings.get("natural").get(0));
}
}
Exception in thread "main" java.lang.ClassCastException: java.util.LinkedHashMap cannot be cast to snakefail.SnakeTest$TagMapping$Mapping
at snakefail.SnakeTest.main(SnakeTest.java:51)
It seems like instead of having Map<String,Map<String,Mapping>> it is creating a Map<String,Map<String,Map>>. Do you know what could be the easiest workaround?
Thank you very much,
Dimi.
--
You received this message because you are subscribed to a topic in the Google Groups "SnakeYAML" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/snakeyaml-core/H3CLnxl3DQI/unsubscribe.
To unsubscribe from this group and all its topics, send an email to snakeyaml-cor...@googlegroups.com.
To post to this group, send email to snakeya...@googlegroups.com.
Visit this group at http://groups.google.com/group/snakeyaml-core.
For more options, visit https://groups.google.com/d/optout.
You received this message because you are subscribed to the Google Groups "SnakeYAML" group.
To unsubscribe from this group and stop receiving emails from it, send an email to snakeyaml-cor...@googlegroups.com.