Moshi: How to handle conflicting Json or qualifier annotations in kotlin

Created on 9 Sep 2019  路  1Comment  路  Source: square/moshi

Consider this case

data class Taco(@property:Json(name = "propertyName") @param:Json(name = "paramName") val seasoning: String)

How should code gen (and possible reflection, need to check if it's also missing handling for this) handle this? Or should it just throw it back to the author as programmer error?

Similar issue exists with json qualifier annotations with parameters if they are duplicated with different parameter values.

Kotlin - reflect bug

Most helpful comment

The parameter annotation shouldn't be honored because it's not a member that participates in serialization. It's just the parameter you use to create an instance. The properties are what is being serialized and so only their annotations should be honored.

>All comments

The parameter annotation shouldn't be honored because it's not a member that participates in serialization. It's just the parameter you use to create an instance. The properties are what is being serialized and so only their annotations should be honored.

Was this page helpful?
0 / 5 - 0 ratings