@Documented
@JsonQualifier
@Retention(value=RUNTIME)
@Target(value={FIELD,METHOD,PARAMETER})
public @interface Wrapped
path.
For example if a json object is:
{
"response": {
"status": "OK"
}
}
And the consumer only cares about the value of status, if using retrofit, a service
method would look like:
@GET("path/")
@Wrapped({"response", "status"}) Call<String> getStatus();
The resulting response returned by response.body() will be a String with the
value "OK".
To leverage from Wrapped ADAPTER_FACTORY must be
added to your Moshi instance:
Moshi moshi = new Moshi.Builder()
.add(Wrapped.ADAPTER_FACTORY)
.build();
DISCLAIMER: The order of added json adapters maters, to ensure
correct un-wrapping behaviour the adapter factory must be the
first custom adapter added to the Moshi.Builder.| Modifier and Type | Fields and Description |
|---|---|
static com.squareup.moshi.JsonAdapter.Factory |
ADAPTER_FACTORY
Builds an adapter that can process a types annotated with
Wrapped. |
| Modifier and Type | Required Element and Description |
|---|---|
java.lang.String[] |
path
The path to the wrapped json path.
|
| Modifier and Type | Optional Element and Description |
|---|---|
boolean |
failOnNotFound
Indicates if the adapter should fail when the json object was not found at the indicated path.
|
public static final com.squareup.moshi.JsonAdapter.Factory ADAPTER_FACTORY
Wrapped.