asJsonString

fun <T> Flow<T>.asJsonString(pretty: Boolean = false, objectMapper: ObjectMapper = defaultObjectMapper): Flow<String>

Converts a flow of objects into a flow of JSON strings, using the provided ObjectMapper.

Return

A flow of JSON strings.

Example usage:

data class Person(val name: String, val age: Int)
val peopleFlow = flowOf(Person("Alice", 30), Person("Bob", 25))

peopleFlow
.asJsonString(pretty = true)
.collect { jsonString -> println(jsonString) }

Parameters

pretty

Whether to output the JSON strings in a human-readable format. Defaults to false.

objectMapper

The ObjectMapper instance to use for converting objects to JSON strings. Defaults to defaultObjectMapper.