Is there a way to setup a Moshi adapter
to automatically create a single Object
or List<Object>
based on the JSON response? Currently, I can do this explicitly. For example, I can receive the following responses:
{
"userId": "1",
"id": "2",
"body": "body...",
"title": "title..."
}
Or
[
{
"userId": "1",
"id": "2",
"body": "body...",
"title": "title..."
}
]
And I would like to create Object
or List<Object>
without having to explicitly specify which one to use.
Using @Eric's comment, I came up with the correct code below:
You can use a JsonQualifier to generalize this. From your example, you might use it like
Here's the code with a test to demonstrate more thouroughly.