I am trying to use @SerialName but is not working ...
# serialization
v
I am trying to use @SerialName but is not working any idea about this ??
d
code pls
v
Copy code
@Serializable
data class HomeDetails(
    val comments: String,
    val description: String,
    val favorites: String,
    @SerialName("first_name")
    val firstName: String,
    @SerialName("hash_tags")
    val hashTags: List<String>,
    @SerialName("last_name")
    val lastName: String,
    @SerialName("post_id")
    val postId: String,
    @SerialName("post_like")
    val postLike: String,
    @SerialName("post_song")
    val postSong: String,
    @SerialName("post_unlike")
    val postUnlike: String,
    @SerialName("singer_type")
    val singerType: String,
    val thumbnail: String
)
d
How does it not work? What is the output?
v
the values of the keys are null where I have used @SerialName and it works when i use @SerializedName(gson serialization)
r
The code seem OK, are you sure you are using
Copy code
import kotlinx.serialization.*
import kotlinx.serialization.json.*
Copy code
val test = HomeDetails("com","desc","fav","name", listOf("list-item"),"last","id",
        "postlike","postsong","unlike","type","thumb")

println(Json.encodeToString(test))
238 Views