use of org.bukkit.configuration.serialization.ConfigurationSerializable in project TriggerReactor by wysohn.
the class TestCommonFunctions method testSerializeLocation.
@Test
public void testSerializeLocation() {
World vWorld = Mockito.mock(World.class);
Location loc1 = new Location(vWorld, 1, 2, 3);
double testX = 3.4;
Assert.assertTrue(fn.serializeLocation(vWorld, 1, 2, 3) instanceof ConfigurationSerializable);
Assert.assertSame(((ConfigurationSerializable) fn.serializeLocation(vWorld, 1, 2, 3)).serialize().get("world"), vWorld.getName());
}
use of org.bukkit.configuration.serialization.ConfigurationSerializable in project TriggerReactor by wysohn.
the class BukkitConfigurationSerializer method deserialize.
@Override
public ConfigurationSerializable deserialize(JsonElement json, Type typeOfT, JsonDeserializationContext context) throws JsonParseException {
JsonObject ser = (JsonObject) json;
// ignore Map without SERIALIZED_TYPE_KEY (they are simple map in such case)
if (ser.get(ConfigurationSerialization.SERIALIZED_TYPE_KEY) == null)
return null;
Map<String, Object> map = new LinkedHashMap<>();
map.put(ConfigurationSerialization.SERIALIZED_TYPE_KEY, ser.get(ConfigurationSerialization.SERIALIZED_TYPE_KEY).getAsString());
try {
Map<String, Object> subs = new HashMap<>();
ser.entrySet().forEach(entry -> {
String key = entry.getKey();
JsonElement value = entry.getValue();
if (value instanceof JsonObject) {
ConfigurationSerializable sub = deserialize(value, typeOfT, context);
if (sub == null) {
// just a Map if JsonObject and is not serialized value
subs.put(key, context.deserialize(value, Map.class));
} else {
subs.put(key, sub);
}
} else {
subs.put(key, context.deserialize(value, Object.class));
}
});
map.putAll(subs);
return ConfigurationSerialization.deserializeObject(map);
} catch (Exception ex) {
throw new RuntimeException("Cannot deserialize " + json, ex);
}
}
Aggregations