Generated MoshiJsonAdapter is generated in wrong class
kmdupr33 opened this issue · 2 comments
I have a Kotlin auto-value class that implements parcelable and needs to be serialized by moshi. I'm using auto-value-parceleable and auto-value-moshi. I've followed the recommendation in issue #70 to include a @JvmStatic
annotation on my jsonAdapter factory method. However, the MoshiJsonAdapter
nested class is generated on $AutoValue_<class_name>
instead of AutoValue_<class_name>
.
That feels like a bug. My class looks like this:
@AutoValue
abstract class LockSelectionModel : Parcelable {
abstract fun brand(): String
companion object {
@JvmStatic fun jsonAdapter(moshi: Moshi): JsonAdapter<LockSelectionModel> =
`$AutoValue_LockSelectionModel`.MoshiJsonAdapter(moshi)
}
}
This is working as intended, unfortunately.
AutoValue adds prefixes of an increasing number of $
symbols for the more extensions that apply to a single AutoValue type. In Java, you can reference nested classes from subtypes of the type in which the class is nested. Kotlin, however, does not allow this trick, which means that you must reference the nested class by directly referring to the class in which it was generated. What's also crazy, is that if you add a third extension to your project it might actually bump the JSON generator later in the chain and it would actually cause your build to fail because they have moved to $$AutoValue_LockSelectionModel
.
wow. bummer. Thanks for clearing that up.