Java Code Examples for org.bukkit.configuration.serialization.ConfigurationSerialization#deserializeObject()
The following examples show how to use
org.bukkit.configuration.serialization.ConfigurationSerialization#deserializeObject() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: SerializationHelper.java From QuickShop-Reremake with GNU General Public License v3.0 | 6 votes |
/** * Parses through the input map to deal with serialized objects a la {@link * ConfigurationSerializable}. * * <p>Called recursively first on Maps and Lists before passing the parsed input over to {@link * ConfigurationSerialization#deserializeObject(java.util.Map)}. Basically this means it will * deserialize the most nested objects FIRST and the top level object LAST. * * @param input the input * @return the object that deserialize */ public static Object deserialize(@NotNull final Map<?, ?> input) { final Map<String, Object> output = new LinkedHashMap<>(input.size()); for (final Map.Entry<?, ?> e : input.entrySet()) { if (e.getValue() instanceof Map) { output.put(e.getKey().toString(), deserialize((Map<?, ?>) e.getValue())); } else if (e.getValue() instanceof List) { output.put(e.getKey().toString(), deserialize((List<?>) e.getValue())); } else { output.put(e.getKey().toString(), e.getValue()); } } if (output.containsKey(ConfigurationSerialization.SERIALIZED_TYPE_KEY)) { try { return ConfigurationSerialization.deserializeObject(output); } catch (IllegalArgumentException ex) { throw new YAMLException("Could not deserialize object", ex); } } return output; }
Example 2
Source File: YamlConstructor.java From Kettle with GNU General Public License v3.0 | 6 votes |
@Override public Object construct(Node node) { if (node.isTwoStepsConstruction()) { throw new YAMLException("Unexpected referential mapping structure. Node: " + node); } Map<?, ?> raw = (Map<?, ?>) super.construct(node); if (raw.containsKey(ConfigurationSerialization.SERIALIZED_TYPE_KEY)) { Map<String, Object> typed = new LinkedHashMap<String, Object>(raw.size()); for (Map.Entry<?, ?> entry : raw.entrySet()) { typed.put(entry.getKey().toString(), entry.getValue()); } try { return ConfigurationSerialization.deserializeObject(typed); } catch (IllegalArgumentException ex) { throw new YAMLException("Could not deserialize object", ex); } } return raw; }
Example 3
Source File: SkriptYamlConstructor.java From skript-yaml with MIT License | 6 votes |
@Override public Object construct(Node node) { if (node.isTwoStepsConstruction()) { throw new YAMLException("Unexpected referential mapping structure. Node: " + node); } Map<?, ?> raw = (Map<?, ?>) super.construct(node); if (raw.containsKey(ConfigurationSerialization.SERIALIZED_TYPE_KEY)) { Map<String, Object> typed = new LinkedHashMap<String, Object>(raw.size()); for (Map.Entry<?, ?> entry : raw.entrySet()) { typed.put(entry.getKey().toString(), entry.getValue()); } try { return ConfigurationSerialization.deserializeObject(typed); } catch (IllegalArgumentException ex) { throw new YAMLException("Could not deserialize object", ex); } } return raw; }
Example 4
Source File: BukkitSerializableAdapterFactory.java From helper with MIT License | 5 votes |
@Override public ConfigurationSerializable read(JsonReader in) { Map<String, Object> map = this.gson.fromJson(in, RAW_OUTPUT_TYPE); if (map == null) { return null; } deserializeChildren(map); return ConfigurationSerialization.deserializeObject(map); }
Example 5
Source File: Serialization.java From PlayerVaults with GNU General Public License v3.0 | 5 votes |
@SuppressWarnings({"unchecked", "rawtypes"}) public static Object deserialize(Map<String, Object> map) { for (Entry<String, Object> entry : map.entrySet()) { if (entry.getValue() instanceof Map) { entry.setValue(deserialize((Map) entry.getValue())); } else if (entry.getValue() instanceof Iterable) { entry.setValue(convertIterable((Iterable) entry.getValue())); } else if (entry.getValue() instanceof Number) { entry.setValue(convertNumber((Number) entry.getValue())); } } return map.containsKey(ConfigurationSerialization.SERIALIZED_TYPE_KEY) ? ConfigurationSerialization.deserializeObject(map) : map; }
Example 6
Source File: BukkitTypeSerializer.java From helper with MIT License | 4 votes |
@Override public ConfigurationSerializable deserialize(TypeToken<?> type, ConfigurationNode from) throws ObjectMappingException { Map<String, Object> map = from.getValue(TYPE); deserializeChildren(map); return ConfigurationSerialization.deserializeObject(map); }