Skip to content
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

Be able to change the default SerializersModule #230

Closed
baillyjamy opened this issue Feb 8, 2021 · 4 comments
Closed

Be able to change the default SerializersModule #230

baillyjamy opened this issue Feb 8, 2021 · 4 comments
Assignees

Comments

@baillyjamy
Copy link

Hello,

I have a Get rest call that I can receive two types of data: B or C.
B and C are children of A. A is an abstract class. There is no serialization / deserialization problem on the JVM. But with Kotlin/JS I need to register my subclasses in a SerializersModule like this :

val module = SerializersModule {
    polymorphic(A::class) {
        subclass(B::class)
        subclass(C::class)
    }
}

Cf : Kotlin/kotlinx.serialization#1077

After registering my module in a Json instance, I can easily deserialize my object in Kotlin/JS env like this :

val jsonString = "{"type":"B",...}"
val format = Json { serializersModule = module }
val instanceB: B = format.decodeFromString(jsonString)

So I would like to change default SerializersModule of an instance of RestClient.
Is it possible or can this feature be implemented?
Or do you have a better solution?

@rjaros
Copy link
Owner

rjaros commented Feb 8, 2021

For now there is no way to define custom serializer modules. You can of course just stick to dynamic/text and serialize/deserialize the data externally.

But I think it should be fairly easy to add support for this in the next release by adding an optional parameter to the RectClient constructor.

@rjaros rjaros self-assigned this Feb 8, 2021
@baillyjamy
Copy link
Author

baillyjamy commented Feb 8, 2021

At the moment I just created a RestClient function extension with a paste copy of remoteCall() and add a parameter for the SerializerModule.
A little ugly but it will be temporary while waiting for the SerializerModule to be added in the constructor.
By the way, it might be interesting to add SerializerModule as a parameter of the two remoteCall() that handle deserialization if we want to use a specific module just once. What do you think about it?

@rjaros
Copy link
Owner

rjaros commented Feb 8, 2021

It could be useful for input data serialization as well, so I think it would be easier to make it available for all methods.

@rjaros
Copy link
Owner

rjaros commented Feb 14, 2021

Released with 4.0.0

@rjaros rjaros closed this as completed Feb 14, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants