1

到目前为止,我已经实现了一个Parcelable类,AutoValue现在我希望能够反序列化它Gson

所以我找到了AutoValue名为auto-value-gson的扩展,我尝试实现一个类,就像 github 页面上的示例一样。

所以我的班级改为:

@AutoValue
public abstract class UploadPhotoResponse implements Parcelable{
    public abstract String getError();
    public abstract UploadPhotoResponseNestedItem getPost();

    public static Builder builder() {
        return new AutoValue_UploadPhotoResponse.Builder();
    }

    @AutoValue.Builder
    public static abstract class Builder {
       public abstract Builder setError(String error);
       public abstract Builder setPost(UploadPhotoResponseNestedItem post);

       public abstract UploadPhotoResponse build();
    }

// This is the new code I have added 
   public static TypeAdapter<UploadPhotoResponse> typeAdapter(Gson gson) {      
        return new AutoValue_UploadPhotoResponse.GsonTypeAdapter(gson);
    }

}

但我收到错误:“无法解析符号GsonTypeAdapter

我正在使用以下依赖项(以防万一丢失):

provided 'com.google.auto.value:auto-value:1.3'
apt 'com.google.auto.value:auto-value:1.3'
apt 'com.ryanharter.auto.value:auto-value-parcel:0.2.5'
apt 'com.ryanharter.auto.value:auto-value-gson:0.4.5'
provided 'com.ryanharter.auto.value:auto-value-gson:0.4.5'
annotationProcessor 'com.gabrielittner.auto.value:auto-value-with:1.0.0'
4

0 回答 0