Issue
I am converting my Json into data object class:
The JSON comes in this format:
entry":[
{
"im:name": {"label":"Growin' Up"}
....
}
So in my data class I have:
data class Entry(
val im:name: ImName
)
But I am having an arror:
Data class primary constructor must have only property (val / var) parameters
I cant change the JSON returned
Solution
im:name
is an invalid variable name in kotlin, if you are using Moshi library for conversion you can use @Json
annoation so your you data class should looks like this:
import com.squareup.moshi.Json
data class Entry(
@Json(name = "im:name")
val imName: ImName
)
If you are using Gson library, you can use @SerializedName
annotation which is simular to @Json
so your data class should looks like this:
import com.google.gson.annotations.SerializedName
data class Entry(
@SerializedName("im:name")
val imName: ImName
)
Answered By - Kaido
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.