Let's assume I have the following data class ``` @...
# serialization
g
Let's assume I have the following data class
Copy code
@Serializable
 data class Accounts(
     val data: List<Account>
 ) {

        @Serializable
        data class Account(
            @SerialName("name")
            val name: String,
            @SerialName("lastname")
            val lastname: String,
        ) 
}
The
Json.encodeToString()
and
decodeToString
returns a JsonObject
Copy code
{
  "data": [
    {
      "name": "Mike",
      "lastname": "Ekim"
    },
    {
      "name": "John",
      "lastname": "Nhoj"
    },
...
How can encode the data class to return a JsonArray? Like the following:
Copy code
data: [{
      "name": "Mike",
      "lastname": "Ekim"
    }, {
      "name": "John",
      "lastname": "Nhoj"
    },
...]
a
Firstly, you don't need
@SerialName
if the json keys match your field names Second. You need a customer serializer that would ignore the data field in Accounts class and just return the list elements Third. If I were you, I wouldn't have an Accounts class, Just a bare Account class is enough to be used with
Json.econdeToString<List<Account>>(listOf())
and
Json.decodeToString<List<Account>>()