@Documented
@JsonQualifier
@Retention(value=RUNTIME)
@Target(value={FIELD,METHOD})
public @interface LastElement
For example if a json object is returned as:
[
{
"some_field": "some_value",
"other_field": "other_value"
}
]
And the consumer only cares about the last element, in the case of using a retrofit service
method the code would look like:
@GET("path/")
@LastElement Call<DataObject> getData();
The resulting response returned by response.body() will be an instance of DataObject with the respective values set.
To leverage from LastElement ADAPTER_FACTORY
must be added to a Moshi instance:
Moshi moshi = new Moshi.Builder()
.add(LastElement.ADAPTER_FACTORY)
.build();
public static final com.squareup.moshi.JsonAdapter.Factory ADAPTER_FACTORY
LastElement.