requireId
Asserts that the JSON:API resource id is present, smart-casting it to String at the call site via a Kotlin Contract.
Most JSON:API resources include a top-level "id" field. A small number of endpoints (e.g. lifetime stats) intentionally omit it, which is why JsonApiResourceDeserializer.deserializeResource declares id as String?. Serializers that require an id should call this function instead of using the unsafe !! operator. After the call the compiler knows id is non-null, so no further assertion or cast is needed.
override fun deserializeResource(
attributes: JsonObject,
id: String?,
relationships: JsonObject?,
included: JsonArray?,
): Player {
requireId(id) // smart-casts id → String
return Player(id = id, …) // id is String here, no !! needed
}Content copied to clipboard
Parameters
id
The id value received from JsonApiResourceDeserializer.deserializeResource.
Throws
SerializationException
if id is null.