Issue
With GSON we used @SerializedName to parse JSON object which didn't have the same key to that of the variable name in Kotlin.
data class User (
@SerializedName("id")
long userId;
@SerializedName("fullName")
String name;
)
In kotlinx.serialization we can serialize an object like this but how to give different JSON key to a varaible during (de)serialization?
@Serializable
data class User (
long userId;
String name;
)
Solution
Use @SerialName like we used @SerializedName in GSON
GSON
data class User (
@SerializedName("id")
long userId;
@SerializedName("fullName")
String name;
)
kotlinx.serialization
@Serializable
data class User (
@SerialName("id")
long userId;
@SerialName("fullName")
String name;
)
Answered By - erluxman
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.