public final class JsonReaders extends Object
Modifier and Type | Method and Description |
---|---|
static List<String> |
collectValuesNamed(com.squareup.moshi.JsonReader reader,
String name) |
static com.squareup.moshi.JsonReader |
enterPath(com.squareup.moshi.JsonReader reader,
String path) |
static com.squareup.moshi.JsonReader |
enterPath(com.squareup.moshi.JsonReader reader,
String path1,
String path2)
This saves you from having to define nested types to read a single value
|
@Nullable public static com.squareup.moshi.JsonReader enterPath(com.squareup.moshi.JsonReader reader, String path1, String path2) throws IOException
Instead of defining two types like this, and double-checking null..
class Response {
Message message;
}
class Message {
String status;
}
JsonAdapter<Response> adapter = moshi.adapter(Response.class);
Message message = adapter.fromJson(body.source());
if (message != null && message.status != null) throw new IllegalStateException(message.status);
You can advance to the field directly.
JsonReader status = enterPath(JsonReader.of(body.source()), "message", "status");
if (status != null) throw new IllegalStateException(status.nextString());
IOException
@Nullable public static com.squareup.moshi.JsonReader enterPath(com.squareup.moshi.JsonReader reader, String path) throws IOException
IOException
public static List<String> collectValuesNamed(com.squareup.moshi.JsonReader reader, String name) throws IOException
IOException
Copyright © 2015–2018 OpenZipkin. All rights reserved.