GraphQLJson

interface GraphQLJson(source)

Deprecated

Legacy GraphQLJson serialization seam for GraphConverter. Use GraphQLTransportCodec with the backend-neutral GraphQLConverterFactory instead.

Pluggable serialization abstraction for GraphQL request and response bodies.

This is the legacy serialization seam of the deprecated GraphConverter path. It is retained in :compat for backward compatibility; new code should use co.anitrend.retrofit.graphql.serialization.GraphQLTransportCodec instead, which is backend-neutral and consumed by the new co.anitrend.retrofit.graphql.converter.GraphQLConverterFactory.

Implementations

ImplementationModuleNotes
GsonGraphQLJson:compatGson-backed. Handles all types including GraphContainer.extensions and GraphQLRequest.extensions.
KotlinxGraphQLJson:compatkotlinx.serialization-backed. Handles parameterized types via JVM reflection extension. GraphContainer.extensions and GraphQLRequest.extensions are @Transient. Recommended for response DTOs.

Implementing a custom backend

class MoshiGraphQLJson(private val moshi: Moshi) : GraphQLJson {
override fun <T : Any> encode(value: T, type: Type?): String = ...
override fun <T : Any> decode(json: String, type: Type): T = ...
}

Register with GraphConverter.create(context, json = MoshiGraphQLJson(...)).

See also

GsonGraphQLJson
KotlinxGraphQLJson

Inheritors

Functions

Link copied to clipboard
abstract fun <T : Any> decode(json: String, type: Type): T

Decode a JSON string into an instance of T.

Link copied to clipboard
abstract fun <T : Any> encode(value: T, type: Type? = null): String

Encode value into a JSON string.