{
* Implementations may use to {@link Moshi#adapter} to compose adapters of other types, or
* {@link Moshi#nextAdapter} to delegate to the underlying adapter of the same type.
*/
- JsonAdapter> create(Type type, Set extends Annotation> annotations, Moshi moshi);
+ @Nullable JsonAdapter> create(Type type, Set extends Annotation> annotations, Moshi moshi);
}
}
diff --git a/moshi/src/main/java/com/squareup/moshi/JsonDataException.java b/moshi/src/main/java/com/squareup/moshi/JsonDataException.java
index 0626263..3bfbf4f 100644
--- a/moshi/src/main/java/com/squareup/moshi/JsonDataException.java
+++ b/moshi/src/main/java/com/squareup/moshi/JsonDataException.java
@@ -15,6 +15,8 @@
*/
package com.squareup.moshi;
+import javax.annotation.Nullable;
+
/**
* Thrown when the data in a JSON document doesn't match the data expected by the caller. For
* example, suppose the application expects a boolean but the JSON document contains a string. When
@@ -31,15 +33,15 @@ public final class JsonDataException extends RuntimeException {
public JsonDataException() {
}
- public JsonDataException(String message) {
+ public JsonDataException(@Nullable String message) {
super(message);
}
- public JsonDataException(Throwable cause) {
+ public JsonDataException(@Nullable Throwable cause) {
super(cause);
}
- public JsonDataException(String message, Throwable cause) {
+ public JsonDataException(@Nullable String message, @Nullable Throwable cause) {
super(message, cause);
}
}
diff --git a/moshi/src/main/java/com/squareup/moshi/JsonEncodingException.java b/moshi/src/main/java/com/squareup/moshi/JsonEncodingException.java
index 625a20e..5c483ca 100644
--- a/moshi/src/main/java/com/squareup/moshi/JsonEncodingException.java
+++ b/moshi/src/main/java/com/squareup/moshi/JsonEncodingException.java
@@ -16,10 +16,11 @@
package com.squareup.moshi;
import java.io.IOException;
+import javax.annotation.Nullable;
/** Thrown when the data being parsed is not encoded as valid JSON. */
public final class JsonEncodingException extends IOException {
- public JsonEncodingException(String message) {
+ public JsonEncodingException(@Nullable String message) {
super(message);
}
}
diff --git a/moshi/src/main/java/com/squareup/moshi/JsonReader.java b/moshi/src/main/java/com/squareup/moshi/JsonReader.java
index 90c04f8..f9b60dd 100644
--- a/moshi/src/main/java/com/squareup/moshi/JsonReader.java
+++ b/moshi/src/main/java/com/squareup/moshi/JsonReader.java
@@ -20,6 +20,7 @@ import java.io.IOException;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
+import javax.annotation.Nullable;
import okio.Buffer;
import okio.BufferedSource;
import okio.ByteString;
@@ -212,7 +213,7 @@ public abstract class JsonReader implements Closeable {
throw new JsonEncodingException(message + " at path " + getPath());
}
- final JsonDataException typeMismatch(Object value, Object expected) {
+ final JsonDataException typeMismatch(@Nullable Object value, Object expected) {
if (value == null) {
return new JsonDataException(
"Expected " + expected + " but was null at path " + getPath());
@@ -351,7 +352,7 @@ public abstract class JsonReader implements Closeable {
*
* @throws JsonDataException if the next token is not null or if this reader is closed.
*/
- public abstract T nextNull() throws IOException;
+ public abstract @Nullable T nextNull() throws IOException;
/**
* Returns the {@linkplain Token#NUMBER double} value of the next token, consuming it. If the next
@@ -400,7 +401,7 @@ public abstract class JsonReader implements Closeable {
* @throws JsonDataException if the next token is not a literal value, if a JSON object has a
* duplicate key.
*/
- public final Object readJsonValue() throws IOException {
+ public final @Nullable Object readJsonValue() throws IOException {
switch (peek()) {
case BEGIN_ARRAY:
List