Does a function exit which returns a JSON-object for a data class
If you’re asking whether that’s one of the methods auto-generated by making a class a
data class, then no, it is not. If you’re asking whether there is some extension or static method in the standard library that knows how to convert data classes specifically to JSON, then, also no, because the
data keyword is not part of the type of a class, or put another way, any method that works for all data class types has to work for all types. There is also no such method that accepts any given type and generates JSON in the non-experimental standard library, so you would probably want to go for a well-established external library, like GSON or Jackson.
There are also 2 kotlin libraries that can help with that. One is kotlinx.serialization (still in development but its developed by the kotlin team). The other is called moshi and is an open source library (partially written in kotlin).
Both support generating adapters at compile time (using katp) which is much faster compared to serialization.