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