Package zipkin2.elasticsearch.internal
Class JsonReaders
- java.lang.Object
-
- zipkin2.elasticsearch.internal.JsonReaders
-
public final class JsonReaders extends java.lang.Object
-
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static java.util.List<java.lang.String>collectValuesNamed(com.squareup.moshi.JsonReader reader, java.lang.String name)static com.squareup.moshi.JsonReaderenterPath(com.squareup.moshi.JsonReader reader, java.lang.String path)static com.squareup.moshi.JsonReaderenterPath(com.squareup.moshi.JsonReader reader, java.lang.String path1, java.lang.String path2)This saves you from having to define nested types to read a single value
-
-
-
Method Detail
-
enterPath
@Nullable public static com.squareup.moshi.JsonReader enterPath(com.squareup.moshi.JsonReader reader, java.lang.String path1, java.lang.String path2) throws java.io.IOExceptionThis saves you from having to define nested types to read a single valueInstead 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());- Throws:
java.io.IOException
-
enterPath
@Nullable public static com.squareup.moshi.JsonReader enterPath(com.squareup.moshi.JsonReader reader, java.lang.String path) throws java.io.IOException- Throws:
java.io.IOException
-
collectValuesNamed
public static java.util.List<java.lang.String> collectValuesNamed(com.squareup.moshi.JsonReader reader, java.lang.String name) throws java.io.IOException- Throws:
java.io.IOException
-
-