encodeDataToJsonElementOrNull

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

Serializes the given data to a JsonElement using the specified data type. Returns the serialized JsonElement if successful, or null if serialization fails.

Return

A JsonElement representing the serialized data, or null if serialization fails.

Parameters

data

The object to be serialized.

dataType

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