Is there a future update coming for kotlinx serial...
# serialization
j
Is there a future update coming for kotlinx serialization which will allow Serializable annotation on a parameter? For instance, I have a data class w/ constructor parameters, one of the is a LocalDateTime field and I need to specify the Serializer for this field. Currently I cannot do this, I have to resort to either removing this parameter from constructor and put in class body which makes the copy function exclude this field that I need to be included, or I don't use a data class and lose the benefits of default copy constructor.
Copy code
@Target(AnnotationTarget.PROPERTY, AnnotationTarget.CLASS, AnnotationTarget.TYPE, // ADD THIS AnnotationTarget.PARAMETER)
//@Retention(AnnotationRetention.RUNTIME) // Runtime is the default retention, also see KT-41082
public annotation class Serializable(
    val with: KClass<out KSerializer<*>> = KSerializer::class // Default value indicates that auto-generated serializer is used
)

EX.
// THIS PRODUCES AN ERROR.
This annotation is not applicable to target 'value parameter'

@Serializable
data class Vehicle(
    @Serializable(with = ISODateWithOffsetSerializer::class),
    var productionDate: LocalDate? = null,
...
plus1 2
g
I guess @Contextual is supposed to solve this by-parameter serializer. Is there a limitation with it?
j
Actually it works as is, I made a mistake and added a comma after the
@Serializable
annotation, which causes an error, once removed it all works as expected now. thanks for your help