JsonApiResourceDeserializer

abstract class JsonApiResourceDeserializer<T>(serialName: String) : DeserializationStrategy<T>

Base deserializer for JSON:API resource objects.

Every resource in the PUBG JSON:API follows the same envelope:

{
"type": "player",
"id": "account.abc123",
"attributes": { … },
"relationships": { … }
}

Subclasses only need to implement deserializeResource to map the pre-parsed id, attributes, relationships, and included into the domain model.

Example

internal object PlayerSerializer : JsonApiResourceDeserializer<Player>("pubgkt.Player") {

override fun deserializeResource(
attributes: JsonObject, id: String, relationships: JsonObject?, included: JsonArray?,
) = Player(id = id, name = attributes.requiredString("name"), …)
}

Parameters

serialName

Unique descriptor name, conventionally the fully-qualified class name of the target type (e.g. "pubgkt.Player").

Constructors

Link copied to clipboard
constructor(serialName: String)

Properties

Link copied to clipboard
open override val descriptor: SerialDescriptor

Functions

Link copied to clipboard
open override fun deserialize(decoder: Decoder): T

DeserializationStrategy entry point.

Link copied to clipboard
fun fromResource(resource: JsonObject, included: JsonArray? = null): T

Deserializes a single resource JsonObject with optional included context.