drtshock loves formatting, so I may as well
This commit is contained in:
@@ -33,12 +33,13 @@ public class Serialization {
|
||||
}
|
||||
return map;
|
||||
}
|
||||
|
||||
private static Object fromJson(Object json) throws JSONException {
|
||||
if (json == JSONObject.NULL) {
|
||||
if(json == JSONObject.NULL) {
|
||||
return null;
|
||||
} else if (json instanceof JSONObject) {
|
||||
} else if(json instanceof JSONObject) {
|
||||
return toMap((JSONObject) json);
|
||||
} else if (json instanceof JSONArray) {
|
||||
} else if(json instanceof JSONArray) {
|
||||
return toList((JSONArray) json);
|
||||
} else {
|
||||
return json;
|
||||
@@ -47,7 +48,7 @@ public class Serialization {
|
||||
|
||||
public static List<Object> toList(JSONArray array) throws JSONException {
|
||||
List<Object> list = new ArrayList<Object>();
|
||||
for (int i = 0; i < array.length(); i++) {
|
||||
for(int i = 0; i < array.length(); i++) {
|
||||
list.add(fromJson(array.get(i)));
|
||||
}
|
||||
return list;
|
||||
@@ -81,7 +82,7 @@ public class Serialization {
|
||||
try {
|
||||
ItemStack item = (ItemStack) deserialize(toMap(new JSONObject(piece)));
|
||||
contents.add(item);
|
||||
} catch (JSONException e) {
|
||||
} catch(JSONException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
@@ -95,17 +96,18 @@ public class Serialization {
|
||||
|
||||
public static Map<String, Object> serialize(ConfigurationSerializable cs) {
|
||||
Map<String, Object> serialized = recreateMap(cs.serialize());
|
||||
for (Entry<String, Object> entry : serialized.entrySet()) {
|
||||
if (entry.getValue() instanceof ConfigurationSerializable) {
|
||||
entry.setValue(serialize((ConfigurationSerializable)entry.getValue()));
|
||||
for(Entry<String, Object> entry:serialized.entrySet()) {
|
||||
if(entry.getValue() instanceof ConfigurationSerializable) {
|
||||
entry.setValue(serialize((ConfigurationSerializable) entry.getValue()));
|
||||
}
|
||||
}
|
||||
serialized.put(ConfigurationSerialization.SERIALIZED_TYPE_KEY, ConfigurationSerialization.getAlias(cs.getClass()));
|
||||
return serialized;
|
||||
}
|
||||
|
||||
public static Map<String, Object> recreateMap(Map<String, Object> original) {
|
||||
Map<String, Object> map = new HashMap<String, Object>();
|
||||
for (Entry<String, Object> entry : original.entrySet()) {
|
||||
for(Entry<String, Object> entry:original.entrySet()) {
|
||||
map.put(entry.getKey(), entry.getValue());
|
||||
}
|
||||
return map;
|
||||
@@ -113,10 +115,11 @@ public class Serialization {
|
||||
|
||||
@SuppressWarnings({ "unchecked", "rawtypes" })
|
||||
public static ConfigurationSerializable deserialize(Map<String, Object> map) {
|
||||
for (Entry<String, Object> entry : map.entrySet()) {
|
||||
// Check if any of its sub-maps are ConfigurationSerializable. They need to be done first.
|
||||
if (entry.getValue() instanceof Map && ((Map)entry.getValue()).containsKey(ConfigurationSerialization.SERIALIZED_TYPE_KEY)) {
|
||||
entry.setValue(deserialize((Map)entry.getValue()));
|
||||
for(Entry<String, Object> entry:map.entrySet()) {
|
||||
// Check if any of its sub-maps are ConfigurationSerializable. They need to be done
|
||||
// first.
|
||||
if(entry.getValue() instanceof Map && ((Map) entry.getValue()).containsKey(ConfigurationSerialization.SERIALIZED_TYPE_KEY)) {
|
||||
entry.setValue(deserialize((Map) entry.getValue()));
|
||||
}
|
||||
}
|
||||
return ConfigurationSerialization.deserializeObject(map);
|
||||
|
||||
Reference in New Issue
Block a user