You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
What is your use-case and why do you need this feature?
Currently, annotating a property with an annotation having MetaSerializable instructs the serialization plugin to treat the annotated data class as serializable.
Doing that onto a field does't instruct the serialization plugin, as it misses the final serializer to be used: contextual ? custom ? something else ?
@MetaSerializable
@SerialInfo
annotationclassMyAnnotation(valdata:String)
@MyAnnotation("some content") // <-- the data class is treated as Serializable and is accessible from the `SerialDescriptor` annotationsdata classMyData(
@MyAnnotation("some content") // <-- ERROR: Serializer has not been found for type 'MyType' as the serializer needs to be explicit or contextualvaltheField:MyType,
)
Describe the solution you'd like
Allow @Serializable to be put on a meta-annotation, allowing us to unify the serializers with their possible configuration as we cannot pass params because of we need to provide a class.
I'm giving you an example: an avro fixed type requires some details to work properly, like its size in bytes. To configure the serializer to encode the content in 10 bytes, we can do like the following:
@Serializable
data classMyData(
@Serializable(with =ByteArrayFixedSerializer::class)
@AvroFixed(size =10)
valtheField:ByteArray,
)
Or even, more generically, for a given BigDecimal where we allow a maximum precision when encoding to a String:
@Serializable
data classMyData(
@Serializable(with =BigDecimalStringSerializer::class)
@DecimalPrecision(digits =3)
valtheField:BigDecimal,
@Serializable(with =AnotherDecimalSerializer::class)
@DecimalPrecision(digits =3) // <--- This is useless as not handled by the AnotherDecimalSerializer implementationvaltheField2:BigDecimal,
)
At the end, here would be the final code, making it clearer for the users IMO as it reduces the noise of needing many annotations:
@SerialInfo
@MetaSerializable
@Serializable(with =ByteArrayFixedSerializer::class)
annotationclassAvroFixed(valsize:Int)
@SerialInfo
@MetaSerializable
@Serializable(with =BigDecimalStringSerializer::class)
annotationclassDecimalPrecision(valdigits:Int)
@Serializable
data classMyData(
@AvroFixed(size =10)
valtheBytesField:ByteArray,
@DecimalPrecision(digits =3)
valtheDecimalField:BigDecimal,
@AvroFixed(size =10)
@DecimalPrecision(digits =3)
valwrongField:BigDecimal,// <--- ERROR: Doesn't compile as we are trying to apply 2 different serializers
@DecimalPrecision(digits =3)
@Serializable(with =AnotherBigDecimalSerializer::class)
valexample1:BigDecimal,// <--- AnotherBigDecimalSerializer takes precedence
@AvroFixed(size =10)
valexample1:BigDecimal,// <--- ERROR: Same as explicit `Serializable` annotation, where we are not able to annotate with a serializer of a different type
)
The text was updated successfully, but these errors were encountered:
What is your use-case and why do you need this feature?
Currently, annotating a property with an annotation having
MetaSerializable
instructs the serialization plugin to treat the annotated data class as serializable.Doing that onto a field does't instruct the serialization plugin, as it misses the final serializer to be used: contextual ? custom ? something else ?
Describe the solution you'd like
Allow
@Serializable
to be put on a meta-annotation, allowing us to unify the serializers with their possible configuration as we cannot pass params because of we need to provide aclass
.I'm giving you an example: an avro
fixed
type requires some details to work properly, like its size in bytes. To configure the serializer to encode the content in 10 bytes, we can do like the following:Or even, more generically, for a given
BigDecimal
where we allow a maximum precision when encoding to a String:At the end, here would be the final code, making it clearer for the users IMO as it reduces the noise of needing many annotations:
The text was updated successfully, but these errors were encountered: