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 encodeValue and decodeValue using serializer<T>() #172

Closed
wants to merge 2 commits into from
Closed

Add encodeValue and decodeValue using serializer<T>() #172

wants to merge 2 commits into from

Conversation

findusl
Copy link
Contributor

@findusl findusl commented Nov 8, 2023

kotlinx.serialization provides a utility function to determine the serializer of a type. It makes using the encodeValue and decodeValue APIs even easier.

I will add more and cleaner tests (not just foo2), if you are interested in this change. I just thought I check before putting in the work. You might have some reason to avoid this function.

@russhwolf
Copy link
Owner

Thanks! I wasn't aware that the auto-detecting serializer machinery worked on non-JVM targets (hadn't really looked closely at that in a couple years), so that's the only reason this isn't already in there.

In addition to tests, I'd also like to add KSerializer-free versions of the rest of the APIs. I can help out there if you're uncertain about anything.

(Once that's done, it's past time to split SettingsSerialization.kt into multiple files, but I'll handle that later in a follow-up)

@findusl
Copy link
Contributor Author

findusl commented Nov 9, 2023

According to this page, it should be part of common. There is some special version for the JVM though, maybe that confused you: https://kotlinlang.org/api/kotlinx.serialization/kotlinx-serialization-core/kotlinx.serialization/serializer.html

I added all the functions and duplicated all the basic tests. I also added test cases for the Exception, when a class is not serializable.

And the file is definitely too big now. But I'll leave that up to you.

@russhwolf
Copy link
Owner

Thanks for this! I've rebased and merged it into a new branch which will make up the 1.2.0 release.

@russhwolf russhwolf closed this Nov 21, 2023
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