toJson

inline fun <T> T.toJson(omitNulls: Boolean = true): String

Writes value of subtype of T to JSON string.

T can be one of the following:

  • String

  • Number and its subclasses

  • Boolean

  • Enum

  • Any

  • T?

  • Json and its subclasses

  • class with custom JsonMapper

  • List, Sequence, Iterable, Collection, Map

  • class with properties of type T1, T2, ... Tn

Parameters

omitNulls

enables omitting of null properties during class serialization.

Throws

if provided type cannot be written to JSON.


fun toJson(value: Any?, type: KType?, omitNulls: Boolean, key: String? = null): Json

Internal function, use toJson or toJsonRepresentation instead.