Fixed issue with adapter serializer

Serialize and deserialize were opposite

In deserializing in flatfile db, there was an odd extra bit of code that
undid the deserialization. I'm not sure why I put that in there and so
I've commented it out for now.
This commit is contained in:
tastybento 2018-05-30 20:23:05 -07:00
parent 6b6ec4c697
commit 53bd51e2f5
4 changed files with 13 additions and 9 deletions

View File

@ -138,11 +138,14 @@ public class FlatFileDatabaseHandler<T> extends AbstractDatabaseHandler<T> {
Adapter adapterNotation = field.getAnnotation(Adapter.class); Adapter adapterNotation = field.getAnnotation(Adapter.class);
if (adapterNotation != null && AdapterInterface.class.isAssignableFrom(adapterNotation.value())) { if (adapterNotation != null && AdapterInterface.class.isAssignableFrom(adapterNotation.value())) {
// A conversion adapter has been defined // A conversion adapter has been defined
// Get the original value
Object value = config.get(storageLocation); Object value = config.get(storageLocation);
method.invoke(instance, ((AdapterInterface<?,?>)adapterNotation.value().newInstance()).serialize(value)); method.invoke(instance, ((AdapterInterface<?,?>)adapterNotation.value().newInstance()).deserialize(value));
/*
* I don't know what this part is for...
if (value != null && !value.getClass().equals(MemorySection.class)) { if (value != null && !value.getClass().equals(MemorySection.class)) {
method.invoke(instance, deserialize(value,propertyDescriptor.getPropertyType())); method.invoke(instance, deserialize(value,propertyDescriptor.getPropertyType()));
} }*/
// We are done here // We are done here
continue; continue;
} }
@ -285,7 +288,7 @@ public class FlatFileDatabaseHandler<T> extends AbstractDatabaseHandler<T> {
if (adapterNotation != null && AdapterInterface.class.isAssignableFrom(adapterNotation.value())) { if (adapterNotation != null && AdapterInterface.class.isAssignableFrom(adapterNotation.value())) {
// A conversion adapter has been defined // A conversion adapter has been defined
try { try {
config.set(storageLocation, ((AdapterInterface<?,?>)adapterNotation.value().newInstance()).deserialize(value)); config.set(storageLocation, ((AdapterInterface<?,?>)adapterNotation.value().newInstance()).serialize(value));
} catch (InstantiationException e) { } catch (InstantiationException e) {
plugin.logError("Could not instatiate adapter " + adapterNotation.value().getName() + " " + e.getMessage()); plugin.logError("Could not instatiate adapter " + adapterNotation.value().getName() + " " + e.getMessage());
} }

View File

@ -15,12 +15,12 @@ public interface AdapterInterface<S,V> {
* @param object - object * @param object - object
* @return serialized object * @return serialized object
*/ */
S serialize(Object object); S deserialize(Object object);
/** /**
* Deserialize object * Deserialize object
* @param object * @param object
* @return deserialized object * @return deserialized object
*/ */
V deserialize(Object object); V serialize(Object object);
} }

View File

@ -20,7 +20,7 @@ public class FlagSerializer implements AdapterInterface<Map<Flag, Integer>, Map<
@SuppressWarnings("unchecked") @SuppressWarnings("unchecked")
@Override @Override
public Map<Flag, Integer> serialize(Object object) { public Map<Flag, Integer> deserialize(Object object) {
Map<Flag, Integer> result = new HashMap<>(); Map<Flag, Integer> result = new HashMap<>();
if (object == null) { if (object == null) {
return result; return result;
@ -41,7 +41,7 @@ public class FlagSerializer implements AdapterInterface<Map<Flag, Integer>, Map<
@SuppressWarnings("unchecked") @SuppressWarnings("unchecked")
@Override @Override
public Map<String, Integer> deserialize(Object object) { public Map<String, Integer> serialize(Object object) {
Map<String, Integer> result = new HashMap<>(); Map<String, Integer> result = new HashMap<>();
if (object == null) { if (object == null) {
return result; return result;

View File

@ -9,7 +9,8 @@ public class PotionEffectListAdapter implements AdapterInterface<List<PotionEffe
@SuppressWarnings("unchecked") @SuppressWarnings("unchecked")
@Override @Override
public List<PotionEffectType> serialize(Object from) { public List<PotionEffectType> deserialize(Object from) {
System.out.println("DEBUG: Deserializing ");
List<PotionEffectType> result = new ArrayList<>(); List<PotionEffectType> result = new ArrayList<>();
if (from instanceof ArrayList) { if (from instanceof ArrayList) {
for (String type: (ArrayList<String>)from) { for (String type: (ArrayList<String>)from) {
@ -21,7 +22,7 @@ public class PotionEffectListAdapter implements AdapterInterface<List<PotionEffe
@SuppressWarnings("unchecked") @SuppressWarnings("unchecked")
@Override @Override
public List<String> deserialize(Object to) { public List<String> serialize(Object to) {
List<String> result = new ArrayList<>(); List<String> result = new ArrayList<>();
if (to instanceof ArrayList) { if (to instanceof ArrayList) {
for (PotionEffectType type: (ArrayList<PotionEffectType>)to) { for (PotionEffectType type: (ArrayList<PotionEffectType>)to) {