mirror of
https://github.com/BentoBoxWorld/BentoBox.git
synced 2025-01-06 16:37:38 +01:00
Improved serialization and deserialization for flatfile db.
This commit is contained in:
parent
f98c5527bc
commit
1fd2b93ce8
@ -311,13 +311,11 @@ public class FlatFileDatabaseHandler<T> extends AbstractDatabaseHandler<T> {
|
|||||||
// Collections need special serialization
|
// Collections need special serialization
|
||||||
if (Map.class.isAssignableFrom(propertyDescriptor.getPropertyType())) {
|
if (Map.class.isAssignableFrom(propertyDescriptor.getPropertyType())) {
|
||||||
// Maps need to have keys serialized
|
// Maps need to have keys serialized
|
||||||
//plugin.getLogger().info("DEBUG: Map for " + storageLocation);
|
|
||||||
if (value != null) {
|
if (value != null) {
|
||||||
Map<Object, Object> result = new HashMap<>();
|
Map<Object, Object> result = new HashMap<>();
|
||||||
for (Entry<Object, Object> object : ((Map<Object,Object>)value).entrySet()) {
|
for (Entry<Object, Object> object : ((Map<Object,Object>)value).entrySet()) {
|
||||||
// Serialize all key types
|
// Serialize all key and values
|
||||||
// TODO: also need to serialize values?
|
result.put(serialize(object.getKey()), serialize(object.getValue()));
|
||||||
result.put(serialize(object.getKey()), object.getValue());
|
|
||||||
}
|
}
|
||||||
// Save the list in the config file
|
// Save the list in the config file
|
||||||
config.set(storageLocation, result);
|
config.set(storageLocation, result);
|
||||||
@ -388,6 +386,18 @@ public class FlatFileDatabaseHandler<T> extends AbstractDatabaseHandler<T> {
|
|||||||
if (clazz.equals(Long.class) && value.getClass().equals(Integer.class)) {
|
if (clazz.equals(Long.class) && value.getClass().equals(Integer.class)) {
|
||||||
return Long.valueOf((Integer) value);
|
return Long.valueOf((Integer) value);
|
||||||
}
|
}
|
||||||
|
if (clazz.equals(Integer.class) && value.getClass().equals(String.class)) {
|
||||||
|
return Integer.valueOf((String)value);
|
||||||
|
}
|
||||||
|
if (clazz.equals(Long.class) && value.getClass().equals(String.class)) {
|
||||||
|
return Long.valueOf((String)value);
|
||||||
|
}
|
||||||
|
if (clazz.equals(Double.class) && value.getClass().equals(String.class)) {
|
||||||
|
return Double.valueOf((String)value);
|
||||||
|
}
|
||||||
|
if (clazz.equals(Float.class) && value.getClass().equals(String.class)) {
|
||||||
|
return Float.valueOf((String)value);
|
||||||
|
}
|
||||||
if (clazz.equals(UUID.class)) {
|
if (clazz.equals(UUID.class)) {
|
||||||
value = UUID.fromString((String)value);
|
value = UUID.fromString((String)value);
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user