Add instanceCreators and constructorLibrary to TypeSerializationLibrary
import org.terasology.reflection.copy.CopyStrategyLibrary;
import org.terasology.reflection.metadata.ClassMetadata;
import org.terasology.reflection.metadata.FieldMetadata;
+import org.terasology.reflection.reflect.ConstructorLibrary;
import org.terasology.reflection.reflect.ReflectFactory;
import org.terasology.rendering.assets.animation.MeshAnimation;
import org.terasology.rendering.assets.material.Material;
private Map<TypeInfo<?>, TypeHandler<?>> typeHandlerCache = Maps.newHashMap();
+ private Map<Type, InstanceCreator<?>> instanceCreators = Maps.newHashMap();
+ private ConstructorLibrary constructorLibrary;
+
private ReflectFactory reflectFactory;
private CopyStrategyLibrary copyStrategies;
public TypeSerializationLibrary(ReflectFactory factory, CopyStrategyLibrary copyStrategies) {
this.reflectFactory = factory;
this.copyStrategies = copyStrategies;
+
+ constructorLibrary = new ConstructorLibrary(instanceCreators, reflectFactory);
+
addTypeHandler(Boolean.class, new BooleanTypeHandler());
addTypeHandler(Boolean.TYPE, new BooleanTypeHandler());
addTypeHandler(Byte.class, new ByteTypeHandler());
@@ -212,6 +219,14 @@ public void addTypeHandlerFactory(TypeHandlerFactory typeHandlerFactory) {
addTypeHandlerFactory(factory);
}
+ public <T> void addInstanceCreator(Class<T> typeClass, InstanceCreator<T> instanceCreator) {
+ addInstanceCreator(TypeInfo.of(typeClass), instanceCreator);
+ }
+
+ public <T> void addInstanceCreator(TypeInfo<T> typeInfo, InstanceCreator<T> instanceCreator) {
+ instanceCreators.put(typeInfo.getType(), instanceCreator);
+ }
+
public TypeHandler<?> getTypeHandler(Type type) {
return getTypeHandler(TypeInfo.of(type));
}
