is always without reflection, that's one of its core concepts. Only exception might be some specific methods that search for the serializer by reflection. But afair you get warned if you use those.
m
mbonnin
11/17/2020, 10:21 PM
Usually you'd want to deserialize queries and not types? (a query contains fields of different types)
mbonnin
11/17/2020, 10:23 PM
But to answer the original question, it depends where the POJO comes from. If you're writing the POJO yourself, you can for sure use kotlinx-serialization. Else you can use graphql-kotlin or apollo-android. They will generate models and parsers based on your queries automatically
m
Marc Knaup
11/18/2020, 3:50 AM
I see a few issues which make it more difficult to use
kotlinx.serialization
for GraphQL parsing.
1) The structure of GraphQL responses is not static but depends on the query. If your queries are static and all result in a very predictable structure then this shouldn’t be an issue though.
2) Kotlin has no notion of union types so those will need special handling.
3) You need a serializer. If you’re in full control over the types then you can use annotations and model around the limitations of
kotlinx.serialization
. If not they you’d have to write your own serializers which is quite painful.
Apart from that… A GraphQL response is simply JSON. Everything that’s JSON you can parse with
kotlinx.serialization
somehow. There are just some limitations you may have to work around.