okkero
02/06/2017, 2:01 PMT
with a property var myVar: U by lazy { ... }
During serialization I want to unwrap the value from the Lazy delegate. No problem. I can do this just fine with a JsonSerializer
.
The problem comes when I want to deserialize the Json back into a T
containing the delegated U
. I haven't found a way to tell Gson the type of the delegated property in a generic way.
When using a JsonDeserializer
you do get the type of the field being deserialized. Because Gson has that type information. However, in the case of delegated properties, the field in question is referring to a delegate. Not a value. If only there were a way to get a hold of the KClass
containing the field, I could get the KProperty
representing the delegated property, and then I could get its type. But it seems that Gson really does not want to give me that option.