mirror of
https://github.com/fankes/moshi.git
synced 2025-10-18 23:49:21 +08:00
Import jsr305 and use it to mark @Nullable stuff. (#297)
This commit is contained in:
@@ -12,6 +12,11 @@
|
||||
<artifactId>moshi-examples</artifactId>
|
||||
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>com.google.code.findbugs</groupId>
|
||||
<artifactId>jsr305</artifactId>
|
||||
<scope>provided</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.squareup.moshi</groupId>
|
||||
<artifactId>moshi</artifactId>
|
||||
|
@@ -24,6 +24,7 @@ import java.io.IOException;
|
||||
import java.lang.annotation.Annotation;
|
||||
import java.lang.reflect.Type;
|
||||
import java.util.Set;
|
||||
import javax.annotation.Nullable;
|
||||
|
||||
public final class DefaultOnDataMismatchAdapter<T> extends JsonAdapter<T> {
|
||||
private final JsonAdapter<T> delegate;
|
||||
@@ -54,7 +55,7 @@ public final class DefaultOnDataMismatchAdapter<T> extends JsonAdapter<T> {
|
||||
|
||||
public static <T> Factory newFactory(final Class<T> type, final T defaultValue) {
|
||||
return new Factory() {
|
||||
@Override public JsonAdapter<?> create(
|
||||
@Override public @Nullable JsonAdapter<?> create(
|
||||
Type requestedType, Set<? extends Annotation> annotations, Moshi moshi) {
|
||||
if (type != requestedType) return null;
|
||||
JsonAdapter<T> delegate = moshi.nextAdapter(this, type, annotations);
|
||||
|
@@ -28,6 +28,7 @@ import java.lang.annotation.Annotation;
|
||||
import java.lang.annotation.Retention;
|
||||
import java.lang.reflect.Type;
|
||||
import java.util.Set;
|
||||
import javax.annotation.Nullable;
|
||||
|
||||
import static java.lang.annotation.RetentionPolicy.RUNTIME;
|
||||
|
||||
@@ -51,8 +52,8 @@ final class Unwrap {
|
||||
|
||||
public static final class EnvelopeJsonAdapter extends JsonAdapter<Object> {
|
||||
public static final JsonAdapter.Factory FACTORY = new Factory() {
|
||||
@Override
|
||||
public JsonAdapter<?> create(Type type, Set<? extends Annotation> annotations, Moshi moshi) {
|
||||
@Override public @Nullable JsonAdapter<?> create(
|
||||
Type type, Set<? extends Annotation> annotations, Moshi moshi) {
|
||||
Set<? extends Annotation> delegateAnnotations =
|
||||
Types.nextAnnotations(annotations, Enveloped.class);
|
||||
if (delegateAnnotations == null) {
|
||||
|
@@ -0,0 +1,3 @@
|
||||
/** Moshi code samples. */
|
||||
@javax.annotation.ParametersAreNonnullByDefault
|
||||
package com.squareup.moshi.recipes;
|
Reference in New Issue
Block a user