-
Notifications
You must be signed in to change notification settings - Fork 620
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Include type alias annotations in SerialDescriptor.annotations
#2702
Comments
No, we currently do not support @SerialInfo-annotations used on types. |
Ic. Ig this issue has now become a feature request - to support |
To implement this would require updates to
Considering that the serial descriptor is linked to the serializer what you are effectively asking for is some sort of lightweight custom serializer (there is a naming problem here as well - names are supposed to be unique, and some format rely on that fact for caching) |
public typealias LangString = @NonLinkedJson(wrapWithValueObject = false) @Serializable(with = LangStringSerializer::class) ImmutableMap<Locale?, ImmutableList<String>> Because it's much more flexible than creating a value class.
One could support type aliases, instead of types, and then just use the typealias' name. |
An alternative would be to support an annotations parameter on |
@Laxystem You can already use |
Ic, thanks. I'll keep this open as a feature request though |
AnnotationTarget.TYPE
annotations appear in SerialDescriptor.annotations
?SerialDescriptor.annotations
The problem with this feature is that in case of usages like @Serializable
class X
@Serializable
class A(val s: List<@SomeInfo X>, val e: List<@SomeOtherInfo X>) Serial descriptor for X is not created every time, it is simply taken from |
That's why I'm proposing to support type aliases and not all types. typealias XWithInfo = @SomeInfo X
// compiles into
typealias XWithInfo = @Serializable(XWithInfoSerializer::class) X
object XWithInfoSerializer : KSerializer<X> by serializer<X>() {
override val descriptor = this@KSerializer.descriptor.withAnnotation(SomeInfo())
}
// which in turn compiles into replacing all usages of XWithInfo with @Serializable(XWithInfoSerializer::class) X |
Type aliases aren't really compiled into anything, they just dissolve into thin air :) I'm not sure if it is possible to provide such substitution with a compiler plugin |
That's the thing, what I'm suggesting is to create custom serializers with the typealias' serial name, that way, you have no conflicts. |
This would be like an extension of
This is not actually valid, the descriptor must have a unique serialName. I'm also not sure that the |
Yes; and type aliases have a full, unique name, with the package and everything. |
I've only seen documentation for
.PROPERTY
and.CLASS
.The text was updated successfully, but these errors were encountered: