GsonGraphQLTransportCodec

class GsonGraphQLTransportCodec(gson: Gson = GsonBuilder().serializeNulls().create()) : GraphQLTransportCodec(source)

Gson-backed implementation of GraphQLTransportCodec.

GsonGraphQLTransportCodec serializes GraphQLOperationRequest envelopes and deserializes GraphQLResponse envelopes with Gson only inside this module. It is the neutral counterpart of the legacy co.anitrend.retrofit.graphql.serialization.gson.GsonGraphQLJson (which moved to :compat with the deprecated GraphConverter flow) and never routes through the generic co.anitrend.retrofit.graphql.model.GraphQLJson seam.

Request encoding

encodeRequest writes the neutral envelope (query, operationName, variables, extensions) using the complete parameterized request Type, so typed variables are resolved from the declared generic arguments rather than the runtime class. With the default Gson instance, absent variables and extensions are written as explicit JSON nulls.

Response decoding

decodeResponse preserves the neutral protocol semantics:

Exception policy

Every failure is wrapped in GraphQLRequestEncodingException or GraphQLResponseDecodingException with the operation or response type context; backend exceptions never leak.

Parameters

gson

A configured Gson instance. Defaults to a Gson with null serialization enabled so absent request fields stay explicit.

See also

Constructors

Link copied to clipboard
constructor(gson: Gson = GsonBuilder().serializeNulls().create())

Functions

Link copied to clipboard
open override fun <T : Any> decodeResponse(body: String, responseType: Type): T
Link copied to clipboard
open override fun encodeRequest(request: GraphQLOperationRequest<*>, requestType: Type): String