use of org.terasology.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);
TypeSerializationLibrary library = new TypeSerializationLibrary(CoreRegistry.get(TypeSerializationLibrary.class));
library.add(UISkin.class, new AssetTypeHandler<>(UISkin.class));
library.add(Border.class, new BorderTypeHandler());
GsonBuilder gsonBuilder = new GsonBuilder().registerTypeAdapterFactory(new CaseInsensitiveEnumTypeAdapterFactory()).registerTypeAdapter(UIData.class, new UIDataTypeAdapter()).registerTypeHierarchyAdapter(UIWidget.class, new UIWidgetTypeAdapter(nuiManager));
for (Class<?> handledType : library.getCoreTypes()) {
gsonBuilder.registerTypeAdapter(handledType, new JsonTypeHandlerAdapter<>(library.getHandlerFor(handledType)));
}
// 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