Parceler / Kotlin:如何使用非数据类?

我想知道如何与Kotlin一起使用Parceler。 这个代码

var x = Intent(); x.putExtra("dog", Parcels.wrap(Dog("wow"))) 

抛出一个exception

parceler.ParcelerRuntimeException:无法为com.loser.stack2.Dog查找生成的Parcelable类,请validation您的类是否正确配置,并且Parcelable类com.loser.stack2.Dog $$ Parcelable是由Parceler生成的。

类是这样的。

 @org.parceler.Parcel open class Dog { @ParcelProperty("f1") var f1:String? = null; @ParcelProperty("f2") var f2:String? = null; @ParcelConstructor constructor();//I do not use this. Only for Parceler. constructor(json:String) { f1=json; f2=json; } } @org.parceler.Parcel class Doge:Dog { @ParcelProperty("f3") var f3:String? = null; @ParcelProperty("f4") var f4:String? = null; @ParcelConstructor constructor():super();//I do not use this. Only for Parceler. constructor(json:String):super(json) { f3=json; f4=json; } } 

的build.gradle

 apply plugin: 'kotlin-kapt' implementation 'org.parceler:parceler-api:1.1.10' 

    Interesting Posts