@Documented
@JsonQualifier
@Retention(value=RUNTIME)
@Target(value={FIELD,METHOD})
public @interface ElementAt
For example if a json object is:
[
{
"some_field": "some_value",
"other_field": "other_value"
},
{
"some_field": "some_value_2",
"other_field": "other_value_2"
}
]
And the consumer only cares about the second element, if using retrofit a service method would
look like:
@GET("path/")
@ElementAt(index = 1) Call<DataObject> getData();
The resulting response returned by response.body() will be an instance of DataObject with the respective values set.
To leverage from ElementAt ADAPTER_FACTORY
must be added to your Moshi instance:
Moshi moshi = new Moshi.Builder()
.add(ElementAt.ADAPTER_FACTORY)
.build();
| Modifier and Type | Fields and Description |
|---|---|
static com.squareup.moshi.JsonAdapter.Factory |
ADAPTER_FACTORY
Builds an adapter that can process a types annotated with
ElementAt. |
| Modifier and Type | Required Element and Description |
|---|---|
int |
index
Represents the index location at which the element will be expected to be.
|
public static final com.squareup.moshi.JsonAdapter.Factory ADAPTER_FACTORY
ElementAt.