use of org.terasology.engine.utilities.gson.CaseInsensitiveEnumTypeAdapterFactory in project Terasology by MovingBlocks.
the class UIFormat method load.
public UIData load(JsonElement element, Locale otherLocale) throws IOException {
NUIManager nuiManager = CoreRegistry.get(NUIManager.class);
TranslationSystem translationSystem = CoreRegistry.get(TranslationSystem.class);
TypeHandlerLibrary library = CoreRegistry.get(TypeHandlerLibrary.class).copy();
library.addTypeHandler(UISkinAsset.class, new AssetTypeHandler<>(UISkinAsset.class));
library.addTypeHandler(UISkin.class, new UISkinTypeHandler());
// TODO: Rewrite to use TypeHandlerLibrary
GsonBuilder gsonBuilder = new GsonBuilder().registerTypeAdapterFactory(new GsonTypeSerializationLibraryAdapterFactory(library)).registerTypeAdapterFactory(new CaseInsensitiveEnumTypeAdapterFactory()).registerTypeAdapter(UIData.class, new UIDataTypeAdapter()).registerTypeHierarchyAdapter(UIWidget.class, new UIWidgetTypeAdapter(nuiManager));
// override the String TypeAdapter from the serialization library
gsonBuilder.registerTypeAdapter(String.class, new I18nStringTypeAdapter(translationSystem, otherLocale));
Gson gson = gsonBuilder.create();
return gson.fromJson(element, UIData.class);
}
Aggregations