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

Add SerialName on 3rd-Party Libs #1250

Open
triplem opened this issue Dec 12, 2020 · 0 comments
Open

Add SerialName on 3rd-Party Libs #1250

triplem opened this issue Dec 12, 2020 · 0 comments
Labels

Comments

@triplem
Copy link

triplem commented Dec 12, 2020

I do have a Domain-Model, which I do not like to dirty with framework and library specific Annotations (in this case @serializable and @SerialName).

So, currently I do use the solution described in the documentation (https://github.com/Kotlin/kotlinx.serialization/blob/master/docs/serializers.md#serializing-3rd-party-classes). This kinda works for the @Serializable-Annotation, but unfortunately seems to be not implemented for the @SerialName.

val domainSerializerModule = SerializersModule {
    polymorphic(Measurement::class) {
        subclass(MeasurementChild1Serializer)
        subclass(MeasurementChild2Serializer)
    }
}

@Serializer(forClass = MeasrurementChild1::class)
object MeasurementChild1Serializer

@Serializer(forClass = MeasurementChild2::class)
object MeasurementChild2Serializer

On using the Serialization, the above returns:

{"type":"application.domain.MeasurementChild1","measure":100}

This is then de-serialized fine, but I would like to avoid the CanonicalName of the class but instead use a defined name. This would make it easier for later refactorings of this class.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

1 participant