![]() kotlin read only var within a sealed data class structure.Androidx Kotlin using Gson, needing to created a nested GSON data class.Kotlin vert.x parsing a JSON String to a Data class using gson always returns null.Populating a Kotlin Data Class using Gson.Kotlin data class create dynamically json of its fields using GSON.How to serialize kotlin sealed class with open val using kotlinx serialization.Exclude a Kotlin data class property/field from serialization/deserialization using gson.Serialize Sealed class within a data class using Gson in kotlin.While I recognise that JsonTypeInfo is a Jackson-specific annotation, perhaps you might consider switching over from Gson if this feature is a must - or you might be able to find an equivalent configuration for Gson which would also include the class identifier in your serialized data. With the annotations used, it required no further configuration for the Jackson instance to properly serialize and de-serialize instances of this sealed class granted that both sides of the communication possessed a uniform definition of the sealed class. My sealed class has been defined as: = JsonTypeInfo.Id.MINIMAL_CLASS, include = JsonTypeInfo.As.PROPERTY, visible = true)Ĭlass SnapshotResponse(val collection: List): FlexibleResponseModel()Ĭlass DifferentialResponse(val collection: List): FlexibleResponseModel()Ĭlass EventDrivenResponse(val collection: List): FlexibleResponseModel()Ĭlass ErrorResponse(val error: String): FlexibleResponseModel() I have successfully serialized and de-serialized a sealed class in the past, with a disclaimer of using Jackson, not Gson as my serialization engine.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |