1 package org.bukkit.configuration.file;
3 import java.util.LinkedHashMap;
6 import org.yaml.snakeyaml.nodes.Node;
7 import org.yaml.snakeyaml.constructor.SafeConstructor;
8 import org.yaml.snakeyaml.error.YAMLException;
9 import org.yaml.snakeyaml.nodes.Tag;
11 import org.bukkit.configuration.serialization.ConfigurationSerialization;
16 this.yamlConstructors.put(Tag.MAP,
new ConstructCustomObject());
19 private class ConstructCustomObject
extends ConstructYamlMap {
21 public Object construct(Node node) {
22 if (node.isTwoStepsConstruction()) {
23 throw new YAMLException(
"Unexpected referential mapping structure. Node: " + node);
26 Map<?, ?> raw = (Map<?, ?>) super.construct(node);
28 if (raw.containsKey(ConfigurationSerialization.SERIALIZED_TYPE_KEY)) {
29 Map<String, Object> typed =
new LinkedHashMap<String, Object>(raw.size());
30 for (Map.Entry<?, ?> entry : raw.entrySet()) {
31 typed.put(entry.getKey().toString(), entry.getValue());
35 return ConfigurationSerialization.deserializeObject(typed);
36 }
catch (IllegalArgumentException ex) {
37 throw new YAMLException(
"Could not deserialize object", ex);
45 public void construct2ndStep(Node node, Object
object) {
46 throw new YAMLException(
"Unexpected referential mapping structure. Node: " + node);