Issue
I have this model that I would like to parse from JSON
:
class CFInsertedValuesStructure {
@SerializedName("id")
val id : Int? = null
@SerializedName("value")
val value : List<String> = listOf();
@SerializedName("field_id")
val field_id : String? = null
}
There is a problem with the parameter "value"
because it isn't always an array of String
, sometimes it could be just a String
type.
So when happens I would like to recognise it and create an array of just one String.
Solution
depending on what library you use the json parsing it may require a custom parsing type e.g. for kotlinx.serialization
you might need to do something like a custom serializer
better still : tell you server-side developer it should always be an array!
Answered By - Robert Munro
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.