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
Hi! I'm currently trying to implement RPC for database access for an admin panel of my pet-project. Server-side database API utilizes Java's LocalDate and LocalDateTime classes, which do not have default serializers in kotlinx.serialization, but I've written custom serializers for them by hand.
I've tried to annotate all LocalDate fields with @Serializable() annotation specifying serializer to use, but that didn't help and build still failed with messages like: DatabaseAbsenceRPCClient.kt:58:58 Serializer has not been found for type 'LocalDate'. To use context serializer as fallback, explicitly annotate type or property with @Contextual. Not including these annotations doesn't affect build's failure to build too. :)
So, my question is: would it be possible to somehow read these annotations in code-generation time and apply them to the generated code too? I think, I'm not the only one who uses custom serializers in kotlinx.serialization, so that would be a nice-to-have feature so we don't have to write boilerplate code to transform from-LocalDate-to-String and back :)
Awesome work on the library, btw! Looks promising!
The text was updated successfully, but these errors were encountered:
Indeed, right now @Serializable(with = ...) is not supported.
Looking at it, I'm not sure this the way to support it, but the use case is valid still.
For the current version, you may use this workaround:
// todo update serializer to work with the value class
@Serializable(with =LocalDateSerializer::class)
@JvmInline
value classLocalDateValue(valvalue:LocalDate)
interfaceDatabaseAbsenceRPC : RPC {
suspendfungetAbsences(date:LocalDateValue): List<AbsenceRecord>
}
We actually support @Contextual annotation, so in general case you should be able to do this:
interfaceDatabaseAbsenceRPC : RPC {
suspendfungetAbsences(@Contextual date:LocalDate): List<AbsenceRecord>
}
// and, for example, with kRPC protocol
rpcClientConfig {
serialization {
json { // for example, json
serializersModule =SerializersModule {
contextual(LocalDate::class) {
// do the thing
}
}
}
}
}
But our current codegen does not copy the parameter annotation, with is a problem on our side. (So it actually works with custom classes as arguments with contextual properties inside them, but not with the method arguments themselves)
I will look into how and which annotations we should support. The case with @contextual will definitely be fixed, and maybe we will add some others.
Hi! I'm currently trying to implement RPC for database access for an admin panel of my pet-project. Server-side database API utilizes Java's
LocalDate
andLocalDateTime
classes, which do not have default serializers in kotlinx.serialization, but I've written custom serializers for them by hand.I've tried to annotate all
LocalDate
fields with@Serializable()
annotation specifying serializer to use, but that didn't help and build still failed with messages like:DatabaseAbsenceRPCClient.kt:58:58 Serializer has not been found for type 'LocalDate'. To use context serializer as fallback, explicitly annotate type or property with @Contextual
. Not including these annotations doesn't affect build's failure to build too. :)Declaration file:
So, my question is: would it be possible to somehow read these annotations in code-generation time and apply them to the generated code too? I think, I'm not the only one who uses custom serializers in kotlinx.serialization, so that would be a nice-to-have feature so we don't have to write boilerplate code to transform from-LocalDate-to-String and back :)
Awesome work on the library, btw! Looks promising!
The text was updated successfully, but these errors were encountered: