mirror of
https://github.com/fankes/moshi.git
synced 2025-10-20 00:19:21 +08:00
Add some short basic docs to JsonAdapter methods (#1313)
This commit is contained in:
@@ -37,14 +37,33 @@ import okio.BufferedSource;
|
|||||||
* <p>Custom JsonAdapter implementations should be designed to be thread-safe.
|
* <p>Custom JsonAdapter implementations should be designed to be thread-safe.
|
||||||
*/
|
*/
|
||||||
public abstract class JsonAdapter<T> {
|
public abstract class JsonAdapter<T> {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 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
|
@CheckReturnValue
|
||||||
public abstract @Nullable T fromJson(JsonReader reader) throws IOException;
|
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
|
@CheckReturnValue
|
||||||
public final @Nullable T fromJson(BufferedSource source) throws IOException {
|
public final @Nullable T fromJson(BufferedSource source) throws IOException {
|
||||||
return fromJson(JsonReader.of(source));
|
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
|
@CheckReturnValue
|
||||||
public final @Nullable T fromJson(String string) throws IOException {
|
public final @Nullable T fromJson(String string) throws IOException {
|
||||||
JsonReader reader = JsonReader.of(new Buffer().writeUtf8(string));
|
JsonReader reader = JsonReader.of(new Buffer().writeUtf8(string));
|
||||||
@@ -55,6 +74,7 @@ public abstract class JsonAdapter<T> {
|
|||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/** Encodes the given {@code value} with the given {@code writer}. */
|
||||||
public abstract void toJson(JsonWriter writer, @Nullable T value) throws IOException;
|
public abstract void toJson(JsonWriter writer, @Nullable T value) throws IOException;
|
||||||
|
|
||||||
public final void toJson(BufferedSink sink, @Nullable T value) throws IOException {
|
public final void toJson(BufferedSink sink, @Nullable T value) throws IOException {
|
||||||
@@ -62,6 +82,7 @@ public abstract class JsonAdapter<T> {
|
|||||||
toJson(writer, value);
|
toJson(writer, value);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/** Encodes the given {@code value} into a String and returns it. */
|
||||||
@CheckReturnValue
|
@CheckReturnValue
|
||||||
public final String toJson(@Nullable T value) {
|
public final String toJson(@Nullable T value) {
|
||||||
Buffer buffer = new Buffer();
|
Buffer buffer = new Buffer();
|
||||||
|
Reference in New Issue
Block a user