Serialize field only if field value is not default
*/
package org.terasology.persistence.typeHandling.coreTypes;
+import com.google.common.base.Defaults;
import com.google.common.collect.Maps;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import java.lang.reflect.Field;
import java.util.Map;
+import java.util.Objects;
/**
* Serializes objects as a fieldName -> fieldValue map. It is used as the last resort while serializing an
@@ -64,7 +66,7 @@ public PersistedData serialize(T value, PersistedDataSerializer serializer) {
continue;
}
- if (val != null) {
+ if (!Objects.equals(val, Defaults.defaultValue(field.getType()))) {
TypeHandler handler = entry.getValue();
PersistedData fieldValue = handler.serialize(val, serializer);
if (fieldValue != null) {
