Hi guys, I’m facing a problem of generalize JSON r...
# squarelibraries
e
Hi guys, I’m facing a problem of generalize JSON response using Moshi. Currently the json can be something like this:
Copy code
{
  "error": 0,
  "err_msg": "",
  "users": [ ... ],
}
Copy code
{
  "error": 0,
  "err_msg": "",
  "movies": [ ... ],
}
The part that is common is the
error
and
err_msg
fields, other than that, the json-key and value can vary depending on which server api I call. I think the way to go is a custom Adapter with
@FromJson fun fromJson(reader: JsonReader): Result<T>
, but I’m struggling on the
<T>
part..
d
I found this article very helpful for non standard json https://medium.com/@BladeCoder/advanced-json-parsing-techniques-using-moshi-and-kotlin-daf56a7b963d @edwardwongtl
e
Thanks, I’ll take a look