encodeDataToStringOrNull

fun encodeDataToStringOrNull(data: Any?, dataType: KType, json: Json? = null): String?(source)

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

Return

A String 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.