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

Provide public API to create typed collection serializers #27

Closed
elizarov opened this issue Oct 16, 2017 · 3 comments
Closed

Provide public API to create typed collection serializers #27

elizarov opened this issue Oct 16, 2017 · 3 comments
Labels

Comments

@elizarov
Copy link
Contributor

There is a need to have top-level serializer extension properties named list, set, and map that construct build-in collection serializers from the element serializers with the following signatures:

val <T> KSerializer<T>.list: KSerializer<List<T>>
val <T> KSerializer<T>.set: KSerializer<Set<T>>
val <K, V> Pair<KSerializer<K>, KSerializer<V>>.map: KSerializer<Map<K, V>>

So, a list of serializable Data items received via REST API in str: String could be deserialized conveniently with:

val list = JSON.parse(str, Data.list) // inferred type of list is List<Data>
@sandwwraith
Copy link
Member

Implemented.

@hagabaka
Copy link

The test case shows how to use it with custom serializers, but how can we use it with a list of objects using the default serializer from @Serializable?

@dany-kun
Copy link

dany-kun commented Apr 5, 2018

You can get your List/Set... serializer from the default serializer of class Foo with Foo.class.serializer().list

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

4 participants