Deserializing countries

Report a typo

You have the following code:

class Tourist(val name: String, val age: Int, val visitedCountries: Array<String>)

val moshi = Moshi.Builder()
    .add(KotlinJsonAdapterFactory())
    .build()

val touristAdapter = moshi.adapter(Tourist::class.java)

val touristString = """
    {"name":"Jacky",
    "age":23, 
    "visitedCountries":["Israel","Argentina","Malaysia"]}""".trimIndent()

val newTourist = touristAdapter.fromJson(touristString)

How can you output all the visited countries in one line in the format ["Israel", "Argentina", "Malaysia"]. Use println() and contentToString().

Enter a short text
___

Create a free account to access the full topic