Deserializing classes with lazy properties using Gson and Kotlin 1.0 beta 4
Since Kotlin 1.0 simply mark the field like this to ignore it during de/serialization: @delegate:Transient val field by lazy { … }
Since Kotlin 1.0 simply mark the field like this to ignore it during de/serialization: @delegate:Transient val field by lazy { … }
I came up with an answer. private static class MyOtherClassTypeAdapter implements JsonDeserializer<List<MyOtherClass>> { public List<MyOtherClass> deserialize(JsonElement json, Type typeOfT, JsonDeserializationContext ctx) { List<MyOtherClass> vals = new ArrayList<MyOtherClass>(); if (json.isJsonArray()) { for (JsonElement e : json.getAsJsonArray()) { vals.add((MyOtherClass) ctx.deserialize(e, MyOtherClass.class)); } } else if (json.isJsonObject()) { vals.add((MyOtherClass) ctx.deserialize(json, MyOtherClass.class)); } else { throw new RuntimeException(“Unexpected JSON … Read more