use of org.spongepowered.api.data.DataManager in project LanternServer by LanternPowered.
the class DataSerializableTypeSerializer method deserialize.
@SuppressWarnings({ "rawtypes", "unchecked" })
@Override
public DataSerializable deserialize(TypeToken<?> type, ConfigurationNode value) throws ObjectMappingException {
final DataManager dataManager = Sponge.getDataManager();
final Optional<DataBuilder<?>> builderOpt = (Optional) dataManager.getBuilder(type.getRawType().asSubclass(DataSerializable.class));
if (!builderOpt.isPresent()) {
throw new ObjectMappingException("No data builder is registered for " + type);
}
final Optional<? extends DataSerializable> built = builderOpt.get().build(ConfigurateTranslator.instance().translate(value));
if (!built.isPresent()) {
throw new ObjectMappingException("Unable to build instance of " + type);
}
return built.get();
}
Aggregations