Is there a way to use Parceler with Kotlin data classes and constructor for serialization without using @ParcelProperty
annotation for each field?
If I try and use library like this:
@Parcel
data class Valve @ParcelConstructor constructor(val size: Int)
I get Error:Parceler: No corresponding property found for constructor parameter arg0
. But if I add @ParcelProperty("size")
it works just fine.
Why is that?
Update:
There are other another way to use this library.
I could just remove @ParcelConstructor
annotation, but then I will get error
Error:Parceler: No @ParcelConstructor annotated constructor and no default empty bean constructor found.
I think (haven't tested it) I also could make all constructor parameters optional and add @JvmOverloads
but that has a side effect that I have to check all properties of the class if they are null or not.
Update 2:
This is what worked for me:
@Parcel
data class Valve(val size: Int? = null)
In short generated Java class must have default empty constructor. One way to achieve that is to do as above - all variables should have default values.