I'm querying Google Sheets and am not quite sure h...
# serialization
c
I'm querying Google Sheets and am not quite sure how to build an object to deserialize this:
Copy code
{
  "values": [
    [
      "Plums",
      5
    ],
    [
      "Apples"
      4
    ]
  ]
}
If the quantities were strings I'd do
values: List<List<String>>
but this fails with
Expected string literal
. Can I do this?
t
List<List<Any>>
-
as is
contract
Alternative - custom serializer
c
With
Any
I get
Serializer has not been found for type "Any"
t
Is it fixed tuple?
[String, Int]
?
c
Yeah - there are actually four fields in there, but they are always the same like that
t
Custom serializer looks like best solution if you want data class like this:
Copy code
data class Row(
    val name: String,
    val count: Int 
)
values: List<Row>
c
hmm, then I get:
Copy code
kotlinx.serialization.json.JsonDecodingException: Unexpected JSON token at offset 78: Expected '{, kind: CLASS'.
t
Do you write custom serializer?
c
ah - I missed that bit. Thought it might be automatic. OK, I'll look into that, thanks.
p
Off topic, but that's a * json format
t
@Paul Woitaschek What does it mean?
p
That having an array of sth random is hard to parse, so that's a bad api
👌 1
c
I thought the same. But it is coming from google sheets so an array of arrays kind of makes sense.
p
Ah that is a sheet, that makes sense
s
You can try to set
isLenient = true
in json configuration. It makes parser more flexible and allows to parse non-quoted literals as strings
👍 4