Does anyone know exactly the place in the kotlinx....
# serialization
v
Does anyone know exactly the place in the kotlinx.serialization source code where plugin generated serializators are generated? or, in other words, where are annotations
@Serializable
processed?
v
I am looking in the following case
Copy code
@SerialInfo
@Target(AnnotationTarget.PROPERTY, AnnotationTarget.TYPE)
annotation class Ann

@Serializable
data class Outer(
    @Ann
    val dates: List<@Ann @Serializable(with = DateSerializer::class) Date>
)
Annotation on property
dates
gets picked up, but on the type does not. And I know this must be possible because
@Serializable
is picked up. Would you give some hints where appropriate modifications in the plugin code must be made?
p
Note that currently lists don't provide a way to specify elementAnnotations either, something you would have to do to correctly expose the type annotations.
@Serializable
is special in that it has a different path, it specifies what serializer to use, not what to put in the descriptors. Btw. as lists are serialized with a standard serializer you can always consider the property annotation to apply as if it were a (list) element annotation.
v
thanks, this is exactly the the workaround I resorted to, but it all get pretty unwieldy if one wants to have annotations for elements of the list, etc. It would be really great if annotation were picked up at the right places.
p
If you really need annotations you can use the new (still experimental) support for creating annotation instances in code, together with a custom serializer that has the right annotations. If you don't want the experimental annotation creation support there is a workaround by using a private serializable that you just extract the annotations out of its descriptor.
Btw. the point of the annotations is for them to be processed by the format. The format can use the one on the property in whatever means it wants, including having an index property to make it apply to the index-th type parameter. What happens with the type parameters is that the outer serializer is constructor with the serializers for the type parameters passed as constructor parameters. Even if the parameters were passed to the serializer, there is no structure to expose type parameter serializers in the descriptor (nor any use site annotations).