Has any thought been given to supporting kotlinx s...
# arrow
r
Has any thought been given to supporting kotlinx serialization? I'm not entirely sure what would be required on the arrow side, maybe just annotating some things with
@Serializable
? Adding support for it from outside arrow is a massive pain because I have to go through this process: https://github.com/Kotlin/kotlinx.serialization/blob/master/docs/custom_serializers.md#about-generic-serializers. (it's actually much easier to copy-paste the arrow classes I want to serialize and annotate them myself, but that's not exactly maintainable)
r
We can explore what it would take them to make them Serializable
Do you have an example with any of the arrow data types?
r
An example of usage or of making it serializable?
r
What it would take for Arrow to make something like
Option
serializable.
or any other data type
depending on the dependencies and style we can make it part of the data types or add an integration module
r
Currently it is complaining about
Nothing
for a reason I don't understand (getting an error inside the compiler plugin), but it should just be a matter of annotating the classes with
@Serializable
.
Might be a compiler plugin bug. For now, I have made some trivial wrappers that work fine:
Copy code
@Serializable
sealed class SerializableEither<out L, out R> {

    @Serializable
    data class Left<out L, out R>(val value: L) : SerializableEither<L, R>()

    @Serializable
    data class Right<out L, out R>(val value: R) : SerializableEither<L, R>()

    fun toEither(): Either<L, R> = when (this) {
        is Left -> Either.Left(value)
        is Right -> Either.Right(value)
    }
}
Logically, there should be a
Nothing
in there for
Left
and
Right
, but the compiler plugin can't handle it right now.
r
Does the Serialization library allow for custom serializers instead of this which looks automated based on instrospection?
r
Then the easiest thing would be to have a module that provides custom serializers like those for the data types
and we bundle it with arrow-core in the uber core jar
r
I disagree, because writing custom serializers for classes with generic type arguments requires implementing the entire serializer yourself, when you could just annotate the class.
r
They don’t support generic serializers?
r
No, they do, but if you want to have the serializer without the annotation, you need to implement it
r
if they don’t support
Nothing
in auto serialization then that is a deal breaker because that is needed for inference
What do you propose we do to support them given that is an issue?
r
Open an issue on their repo
r
In whatever case we will offer a solution if people need us to support Serialization, others have asked too If I recall. The issue is that most of the maintainers are focused on other areas but eventually we will have to bring support for Serialization
r
r
@Ryan Benasutti I added some thoughts on the issue. I don’t think is about supporting a general value for
Nothing
. I think the issue here is that Nothing in type argument position is a valid bottom type for any higher kinded wrapped value because it denotes no inhabitants of the parametric type but not of the type.
And it should be just simply ignored by the Serializer when found in type argument position as it’s serializer is not necessary to form any of the product types you need to inductively derive a serializer.
d
Hello, I see it's been a while. Serialization 1.0 was just announced, however the issue with
Nothing
hasn't been resolved yet. @raulraja are there any plans to add support for this in arrow or are you waiting for the issue to be fixed?
r
Hi @dephinera, we are currently migrating Arrow to the new IR backend in 1.4. If there is no cost or dependencies added to Arrow in making the types serializable it’s something we can look into.
👍 1