I am using `json` serialization/de-serialization a...
# serialization
a
I am using
json
serialization/de-serialization and one of my usecase requires me to
POST
nd-json
format (multi-query search on elastic search). Any hint or idea on how I can achieve the behaviour?
d
Probably write your own body content provider, that outputs each item separated by lines.
What http client are you using? Ktor? Something else?
a
I am using Retrofit (okhttp)
d
I’m not familiar with retrofit, so you’ll have to find the correct api yourself, but see if there is a way to produce a custom request body.
a
Resolved to using
source
query param. The passed param conforms to
application/x-ndjson
. The workaround is
Copy code
List<JsonObject>.joinToString("\n", suffix = "\n", transform = { jsonObject -> jsonObject.toString() })
This yields the string as
Copy code
{ "index": "…"}
{ /* query or aggs */ }
{ "index": "…"}
{ /* query or aggs */ }
Definitely not ideal, but works ..