parceler icon indicating copy to clipboard operation
parceler copied to clipboard

Naming conventions for properties in class

Open Gloix opened this issue 7 years ago • 4 comments

Hi, I'm getting No corresponding property found for constructor parameter ID and No corresponding property found for constructor parameter isValid for the following Kotlin class:

@Parcel(Parcel.Serialization.BEAN)
data class MyClass @ParcelConstructor constructor(
    var ID: String? = null,
    val isValid: Boolean
)

I discovered that by lowercasing the ID property and removing 'is' from isValid works as expected. Is Parceler sensitive to proper naming conventions? (a.k.a. camel case properties). Why are "is" prefixed properties not valid?

Gloix avatar Oct 29 '18 15:10 Gloix

Sorry @Gloix, I guess I missed this one from a few days ago... do you know what Java is generated from this Kotlin class?

johncarl81 avatar Nov 08 '18 20:11 johncarl81

No worries. From Java, methods are boolean isValid(), void setID(String s) and String getID().

Gloix avatar Nov 08 '18 21:11 Gloix

Hmm, I bet the isValid name in the constructor is colliding with the valid property name of isValid. Does it work if you change isValid to valid? Or does it work if you clarify the constructor argument with @ParcelProperty("valid") var is Valid: Boolean ?

johncarl81 avatar Nov 08 '18 21:11 johncarl81

... I should just make a KOTLIN specific strategy to handle weird issues with kotlin beans.

johncarl81 avatar Nov 08 '18 21:11 johncarl81