Skip to content

Add more custom serializers for kotlinx serialization#2978

Merged
fire-light42 merged 4 commits into
recloudstream:masterfrom
Luna712:add-serializers
Jul 12, 2026
Merged

Add more custom serializers for kotlinx serialization#2978
fire-light42 merged 4 commits into
recloudstream:masterfrom
Luna712:add-serializers

Conversation

@Luna712

@Luna712 Luna712 commented Jun 29, 2026

Copy link
Copy Markdown
Contributor

This also seperates the tests, and test serializers that are in library, using commonMain tests rather than testing library serializers in androidTest also. The tests in androidTest have been changed to just test UriSerializer, which is the only one actually there.

This adds numerous other serializers to replicate Jackson mapper configuration behavior, that some extensions will need (such as InternetArchiveProvider) This adds support for replicating the following behaviors:

jacksonObjectMapper().apply {
    configure(DeserializationFeature.ACCEPT_SINGLE_VALUE_AS_ARRAY, true)
    configure(DeserializationFeature.ACCEPT_EMPTY_ARRAY_AS_NULL_OBJECT, true)
    configure(DeserializationFeature.ACCEPT_EMPTY_STRING_AS_NULL_OBJECT, true)
    configure(DeserializationFeature.ACCEPT_FLOAT_AS_INT, true)
}

For DeserializationFeature.ACCEPT_FLOAT_AS_INT, which allows converting both Int or Long to a Float, it was split into two separate serializers, FloatAsIntSerializer and FloatAsLongSerializer, as it was complex to do both at once and I also figured it would be nice to allow splitting this before for more explicit control.

Another difference is that unlike custom mappers that can be applied to the whole thing, when migrated from Jackson to Kotlinx, it would have to drop custom mappers entirely, use the normal parseJson/tryParseJson/etc... and be explicit about what classes need this, which in my personal opinion is better to be more explicit and allows us to be more unified in how the AppUtils methods are used more accept under some way more rare circumstances where you may need a custom Json instance.

I also explained how to use all the serializers in doc comments. We could also later add more serializers if necessary.

Luna712 added 4 commits June 29, 2026 13:59
This also seperates the tests, and test serializers that are in library, using commonMain tests rather than testing library serializers in androidTest also. The tests in androidTest have been changed to just test UriSerializer, which is the only one actually there.

This adds numerous other serializers to replicate Jackson mapper configuration behavior, that some extensions will need (such as [InternetArchiveProvider](https://github.com/recloudstream/extensions/blob/cf16b3b45cda911a36ddca69f9acbe4763c6a4b1/InternetArchiveProvider/src/main/kotlin/recloudstream/InternetArchiveProvider.kt#L47-L56)) This adds support for replicating the following behaviors:
```kt
jacksonObjectMapper().apply {
    configure(DeserializationFeature.ACCEPT_SINGLE_VALUE_AS_ARRAY, true)
    configure(DeserializationFeature.ACCEPT_EMPTY_ARRAY_AS_NULL_OBJECT, true)
    configure(DeserializationFeature.ACCEPT_EMPTY_STRING_AS_NULL_OBJECT, true)
    configure(DeserializationFeature.ACCEPT_FLOAT_AS_INT, true)
}
```
For `DeserializationFeature.ACCEPT_FLOAT_AS_INT`, which allows converting both Int or Long to a Float, it was split into two separate serializers, `FloatAsIntSerializer` and `FloatAsLongSerializer`, as it was complex to do both at once and I also figured it would be nice to allow splitting this before for more explicit control.

Another difference is that unlike custom mappers that can be applied to the whole thing, when migrated from Jackson to Kotlinx, it would have to drop custom mappers entirely, use the normal `parseJson`/`tryParseJson`/etc... and be explicit about what classes need this, which in my personal opinion is better to be more explicit and allows us to be more unified in how the `AppUtils` methods are used more accept under some way more rare circumstances where you may need a custom `Json` instance.

I also explained how to use all the serializers in doc comments. We could also later add more serializers if necessary.

@fire-light42 fire-light42 left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Great to drop custom mappers!

Always a pleasure to review well-written code with tests and great doc-comments.

@fire-light42 fire-light42 merged commit 7b3c938 into recloudstream:master Jul 12, 2026
2 checks passed
@Luna712 Luna712 deleted the add-serializers branch July 12, 2026 22:40
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

Successfully merging this pull request may close these issues.

2 participants