com.artemis.io.ComponentLookupSerializer Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of artemis-odb-serializer-json Show documentation
Show all versions of artemis-odb-serializer-json Show documentation
Fork of Artemis Entity System Framework.
package com.artemis.io;
import com.artemis.Component;
import com.artemis.World;
import com.artemis.utils.reflect.ClassReflection;
import com.artemis.utils.reflect.ReflectionException;
import com.esotericsoftware.jsonbeans.Json;
import com.esotericsoftware.jsonbeans.JsonSerializer;
import com.esotericsoftware.jsonbeans.JsonValue;
import java.util.IdentityHashMap;
import java.util.Map;
public class ComponentLookupSerializer implements JsonSerializer {
private World world;
private IdentityHashMap, String> componentMap;
public ComponentLookupSerializer(World world) {
this.world = world;
}
public void setComponentMap(IdentityHashMap, String> componentMap) {
this.componentMap = componentMap;
}
@Override
public void write(Json json, IdentityHashMap object, Class knownType) {
json.writeObjectStart();
for (Map.Entry, String> entry : componentMap.entrySet()) {
json.writeValue(entry.getKey().getName(), entry.getValue());
}
json.writeObjectEnd();
}
@Override
public IdentityHashMap read(Json json, JsonValue jsonData, Class type) {
IdentityHashMap, String> componentMap
= new IdentityHashMap, String>();
JsonValue component = jsonData.child;
try {
while (component != null) {
Class c = ClassReflection.forName(component.name());
componentMap.put(c, component.asString());
component = component.next;
}
} catch (ReflectionException e) {
throw new RuntimeException(e);
}
return componentMap;
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy