Hi there, I’m trying to pass a json object into a ...
# kotless
h
Hi there, I’m trying to pass a json object into a post request, my function looks like this:
Copy code
@Post("/createItems")
fun createItems(info: ItemInfo): HttpResponse {
    ItemStorage.createItems(info)
    return HttpResponse(201, MimeType.JSON, "")
}

data class ItemInfo(
    val name: String,
    val count: Int,
    val details: String,
)
But when I make the following call, I get an error that the parameter is missing:
Copy code
POST /1/createItems HTTP/1.1
Accept: application/json, */*;q=0.5

{
    "info": {
        "count": 10,
        "details": "test1 details",
        "name": "test1"
    }
}
Response is:
Copy code
HTTP/1.1 500 Internal Server Error
Connection: keep-alive
Content-Length: 35
Content-Type: text/plain
Date: Wed, 03 Mar 2021 13:56:42 GMT

Required argument 'info' is missing
Are json objects not supported? I can rewrite to flatten object, but it seems like one of the main value propositions of kotless is being able to work with kotlin and objects in a clean way and without all the normal headache of marshalling/unmarshalling things
t
Hm, we had this discussion above — basically automatic demarshalling from post body was disabled, but probably we should return it
Still you can use Ktor which has this support
c
Hi @Hunter Kelly, see my question / solution here: https://kotlinlang.slack.com/archives/CKS388069/p1608292637036900
But in the end we decided to switch to Ktor