use of org.terasology.reflection.metadata.FieldMetadata in project Terasology by MovingBlocks.
the class MappedContainerTypeHandler method deserialize.
@Override
public T deserialize(PersistedData data, DeserializationContext context) {
try {
T result = clazz.newInstance();
for (Map.Entry<String, PersistedData> entry : data.getAsValueMap().entrySet()) {
FieldMetadata fieldInfo = fieldByName.get(UriUtil.normalise(entry.getKey()));
if (fieldInfo != null) {
TypeHandler handler = mappedFields.get(fieldInfo);
Object val = handler.deserialize(entry.getValue(), context);
fieldInfo.setValue(result, val);
}
}
return result;
} catch (Exception e) {
logger.error("Unable to deserialize {}", data, e);
}
return null;
}
use of org.terasology.reflection.metadata.FieldMetadata in project Terasology by MovingBlocks.
the class MetadataBuilderTest method testPrivateField.
@Test
public void testPrivateField() throws Exception {
DefaultClassMetadata<PrivateField> metadata = new DefaultClassMetadata<>(new SimpleUri(), PrivateField.class, factory, copyStrategyLibrary);
assertNotNull(metadata);
assertEquals(1, metadata.getFieldCount());
FieldMetadata fieldMetadata = metadata.getField("name");
assertNotNull(fieldMetadata);
assertEquals(String.class, fieldMetadata.getType());
assertEquals("name", fieldMetadata.getName());
assertNotNull(metadata.newInstance());
}
Aggregations