1

Can't make the parcelization work as expceted. That is the class:

@Parcelize
class ResultsWrapper<T>(
    @SerializedName("results") var results: T
): Parcelable

In that case it says: Type is not directly supported by 'Parcelize'. Annotate the parameter type with '@RawValue' if you want it to be serialized using 'writeValue()'

Parcelization can't know the T implements Parcelable? No problem. Writing like this:

@Parcelize
class ResultsWrapper<T: Parcelable>(
    @SerializedName("results") var results: T
): Parcelable

Now there is no compilation error, but there is build time error:

error: non-static type variable T cannot be referenced from a static context (in newArray and createFromParcel generated functions in static Creator)

Using @RawValue lead to same error.

How to make it right?

Shmuel
  • 488
  • 1
  • 6
  • 18
  • See [this](https://stackoverflow.com/questions/18797399/is-it-possible-to-parcel-a-generic-class). Seems like the generator runs into the same problem as the OP of that post. You'll have to implement `Parcelable` manually. See the answer by Bulwinkel. – Sweeper Aug 10 '21 at 02:11
  • Though I don't think you need to do the whole thing. You should be able to just do `var results: @RawValue T` and provide a custom `Parceler` companion object. – Sweeper Aug 10 '21 at 02:21
  • Looks like your `ResultsWrapper` works for me. What's your `kotlin` and `kotlin-gradle-plugin` versions? How many modules in your project? Does `kotlin-parcelize` plugin (previously `kotlin-android-extensions`) declared in the module with `ResultsWrapper` class? – Vadik Sirekanyan Aug 10 '21 at 13:31

0 Answers0