Search in sources :

Example 1 with GsonTypeSerializationLibraryAdapterFactory

use of org.terasology.engine.persistence.typeHandling.gson.GsonTypeSerializationLibraryAdapterFactory 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);
}
Also used : TranslationSystem(org.terasology.engine.i18n.TranslationSystem) GsonTypeSerializationLibraryAdapterFactory(org.terasology.engine.persistence.typeHandling.gson.GsonTypeSerializationLibraryAdapterFactory) UISkinAsset(org.terasology.nui.skin.UISkinAsset) GsonBuilder(com.google.gson.GsonBuilder) Gson(com.google.gson.Gson) UISkinTypeHandler(org.terasology.engine.persistence.typeHandling.extensionTypes.UISkinTypeHandler) UIData(org.terasology.nui.asset.UIData) CaseInsensitiveEnumTypeAdapterFactory(org.terasology.engine.utilities.gson.CaseInsensitiveEnumTypeAdapterFactory) TypeHandlerLibrary(org.terasology.persistence.typeHandling.TypeHandlerLibrary) NUIManager(org.terasology.engine.rendering.nui.NUIManager)

Aggregations

Gson (com.google.gson.Gson)1 GsonBuilder (com.google.gson.GsonBuilder)1 TranslationSystem (org.terasology.engine.i18n.TranslationSystem)1 UISkinTypeHandler (org.terasology.engine.persistence.typeHandling.extensionTypes.UISkinTypeHandler)1 GsonTypeSerializationLibraryAdapterFactory (org.terasology.engine.persistence.typeHandling.gson.GsonTypeSerializationLibraryAdapterFactory)1 NUIManager (org.terasology.engine.rendering.nui.NUIManager)1 CaseInsensitiveEnumTypeAdapterFactory (org.terasology.engine.utilities.gson.CaseInsensitiveEnumTypeAdapterFactory)1 UIData (org.terasology.nui.asset.UIData)1 UISkinAsset (org.terasology.nui.skin.UISkinAsset)1 TypeHandlerLibrary (org.terasology.persistence.typeHandling.TypeHandlerLibrary)1