Home > OS >  How do I create a list in JSON equivalent to a list on Kotlin?
How do I create a list in JSON equivalent to a list on Kotlin?

Time:05-01

I'm learning Ktor and trying to test a POST request implementation I made using the example model given here. However, I have no idea how to make a proper list in JSON that Ktor could read and deserialize as a list.

I've tried:

{
  "number": "2022-04-28",
  "contents": {
    "OrderItem": {
      "item": "Tea",
      "amount": 5,
      "price": 2.99
    },
    "OrderItem": {
      "item": "Coffee",
      "amount": 2,
      "price": 4.99
    }
  }
}

But I get an internal server error whenever I try to send the POST request.

CodePudding user response:

contents should be a list [] of objects

{
  "number": "2022-04-28",
  "contents": [
    {
      "item": "Tea",
      "amount": 5,
      "price": 2.99
    },
    {
      "item": "Coffee",
      "amount": 2,
      "price": 4.99
    }
  ]
}
  • Related