Using deserialized instance's delegation throws NullPointerException
See original GitHub issueThe following code throws NullPointerException. Is it expected behavior?
package sample
import kotlinx.serialization.Serializable
import kotlinx.serialization.json.JSON
interface IntId {
var id: Int
}
interface IData {
var msg: String?
}
@Serializable
data class Data(
override var msg: String? = null
) : IData
@Serializable
data class IdData(
override var id: Int,
var data: Data
) : IntId, IData by data
inline fun <reified T : Any> deserialTest(root: T): T {
val json = JSON.stringify(root)
println(json)
val obj = JSON.parse<T>(json)
println(obj)
return obj
}
fun main(args: Array<String>) {
val src = IdData(3, Data("asdf"))
val restored = deserialTest(src)
println(restored.msg)
}
> Task :run FAILED
{"id":3,"data":{"msg":"asdf"}}
IdData(id=3, data=Data(msg=asdf))
Exception in thread "main" java.lang.NullPointerException
at sample.IdData.getMsg(XSerialization.kt)
at sample.XSerializationKt.main(XSerialization.kt:38)
Issue Analytics
- State:
- Created 5 years ago
- Reactions:2
- Comments:7 (4 by maintainers)
Top Results From Across the Web
Jackson & JSONAnySetter: NullPointer Exception during ...
The problem is that the defaultSerializer instance, you are using inside your HidableSerializer, is a ResolvableSerializer (BeanSerializer), ...
Read more >delegate:Transient val by lazy fails with NullPointerException ...
Workaround is to remove the @delegate:Transient annotation, which however increases serialized class size.
Read more >Can Your Kafka Consumers Handle a Poison Pill? - Confluent
Now, when either the key or value delegate fails to deserialize a poison pill, the ErrorHandlingDeserializer returns a null value and adds a ......
Read more >NullPointerException (Java Platform SE 8 ) - Oracle Help Center
Thrown when an application attempts to use null in a case where an object is required. These include: Calling the instance method of...
Read more >[Solved] com.fasterxml.jackson.databind.exc ...
Example of InvalidDefinitionException In this given example deserialing ... exist): cannot deserialize from Object value (no delegate- or ...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
Delegation does seem to work fine for me, if the Object is instantiated by default in the constructor:
This is an accessible workaround for me, Thanks