1

Maybe this is simple, but I'm missing how to do this. I'm using GSON, kotlin, and retrofit

Data.json

{
  "array1":[1,2],
  "array2":[1,2]
}

DataObject.kt

data class DataObject(array1: List<Int>, array2: List<Int>)

The the above fails to deserialize the arrays.

Community
  • 1
  • 1
soundsofpolaris
  • 596
  • 3
  • 12
  • Considering the kotlin code you've provided is not valid and wouldnt compile, I don't see how this code would even get to the deserialization step. – Kiskae Apr 10 '18 at 22:14

1 Answers1

0

This is a running example:

data class DataObject(val array1: List<Int>, val array2: List<Int>)

fun main(args: Array<String>) {
    val json = """{"array1":[1,2],"array2":[1,2]}"""
    println(Gson().fromJson(json, DataObject::class.java))
    //DataObject(array1=[1, 2], array2=[1, 2])
}

I've only changed the arguments of DataObject to be val, which is required for data classes (var also works).

s1m0nw1
  • 76,759
  • 17
  • 167
  • 196