AutoValue with GsonTypeAdapter in Kotlin

Viewed 478

I am trying to integrate Kotlin in an existing android Java project. After making the changes in the build and adding Kotlin to the project I can't find a solution to my AutoValue classes that have GsonTypeAdapter there doesn't seem to be support for this.

    @AutoValue
    public abstract class MediaObject implements Parcelable {

    public static TypeAdapter<MediaObject> typeAdapter(Gson gson) {
        return new AutoValue_MediaObject.GsonTypeAdapter(gson);
    }

    @SerializedName("mimetype")
    public abstract String getMimeType();

    @SerializedName("url")
    public abstract String getUri();
}

My Gson builder:

GsonBuilder().registerTypeAdapterFactory(new AutoValueGsonTypeAdapterFactory())

Any suggestions how to resolve this or what to use instead?

1 Answers

Just dont use it. If it is for Retrofit, you can just use .addConverterFactory(GsonConverterFactory.create()) and the kotlin data class.In your case, you need to remove MediaObject java class, and create data class:

data class MediaObject(
    @SerializedName("mimetype")
    val mimetypeString:String,

    @SerializedName("url")
    val uri:String)
Related