encodeDataToJsonElement

fun encodeDataToJsonElement(data: Any?, dataType: KType, json: Json? = null): JsonElement(source)

Serializes the given data to a JsonElement using the specified data type. Throws SerializationException if serialization fails.

Return

A JsonElement representing the serialized data.

Parameters

data

The object to be serialized.

dataType

The type of the object used to find the appropriate serializer.

Throws

if serialization fails or no serializer is found for the data type.

if no serializer is found for the specified data type.