From 797140c5cf0e376387b99fcaa8cc00988d1ffbb5 Mon Sep 17 00:00:00 2001 From: Zac Sweers Date: Sat, 13 Mar 2021 20:52:40 -0500 Subject: [PATCH] Add some short basic docs to JsonAdapter methods (#1313) --- .../java/com/squareup/moshi/JsonAdapter.java | 21 +++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/moshi/src/main/java/com/squareup/moshi/JsonAdapter.java b/moshi/src/main/java/com/squareup/moshi/JsonAdapter.java index b7787f4..4cf1180 100644 --- a/moshi/src/main/java/com/squareup/moshi/JsonAdapter.java +++ b/moshi/src/main/java/com/squareup/moshi/JsonAdapter.java @@ -37,14 +37,33 @@ import okio.BufferedSource; *

Custom JsonAdapter implementations should be designed to be thread-safe. */ public abstract class JsonAdapter { + + /** + * Decodes a nullable instance of type {@link T} from the given {@code reader}. + * + * @throws JsonDataException when the data in a JSON document doesn't match the data expected by + * the caller. + */ @CheckReturnValue public abstract @Nullable T fromJson(JsonReader reader) throws IOException; + /** + * Decodes a nullable instance of type {@link T} from the given {@code source}. + * + * @throws JsonDataException when the data in a JSON document doesn't match the data expected by + * the caller. + */ @CheckReturnValue public final @Nullable T fromJson(BufferedSource source) throws IOException { return fromJson(JsonReader.of(source)); } + /** + * Decodes a nullable instance of type {@link T} from the given {@code string}. + * + * @throws JsonDataException when the data in a JSON document doesn't match the data expected by + * the caller. + */ @CheckReturnValue public final @Nullable T fromJson(String string) throws IOException { JsonReader reader = JsonReader.of(new Buffer().writeUtf8(string)); @@ -55,6 +74,7 @@ public abstract class JsonAdapter { return result; } + /** Encodes the given {@code value} with the given {@code writer}. */ public abstract void toJson(JsonWriter writer, @Nullable T value) throws IOException; public final void toJson(BufferedSink sink, @Nullable T value) throws IOException { @@ -62,6 +82,7 @@ public abstract class JsonAdapter { toJson(writer, value); } + /** Encodes the given {@code value} into a String and returns it. */ @CheckReturnValue public final String toJson(@Nullable T value) { Buffer buffer = new Buffer();