Search in sources :

Example 1 with CaseInsensitiveEnumTypeAdapterFactory

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);
}
Also used : TranslationSystem(org.terasology.i18n.TranslationSystem) GsonBuilder(com.google.gson.GsonBuilder) UISkin(org.terasology.rendering.nui.skin.UISkin) Gson(com.google.gson.Gson) CaseInsensitiveEnumTypeAdapterFactory(org.terasology.utilities.gson.CaseInsensitiveEnumTypeAdapterFactory) BorderTypeHandler(org.terasology.persistence.typeHandling.mathTypes.BorderTypeHandler) TypeSerializationLibrary(org.terasology.persistence.typeHandling.TypeSerializationLibrary) NUIManager(org.terasology.rendering.nui.NUIManager)

Aggregations

Gson (com.google.gson.Gson)1 GsonBuilder (com.google.gson.GsonBuilder)1 TranslationSystem (org.terasology.i18n.TranslationSystem)1 TypeSerializationLibrary (org.terasology.persistence.typeHandling.TypeSerializationLibrary)1 BorderTypeHandler (org.terasology.persistence.typeHandling.mathTypes.BorderTypeHandler)1 NUIManager (org.terasology.rendering.nui.NUIManager)1 UISkin (org.terasology.rendering.nui.skin.UISkin)1 CaseInsensitiveEnumTypeAdapterFactory (org.terasology.utilities.gson.CaseInsensitiveEnumTypeAdapterFactory)1