S.
12/18/2024, 3:01 PMdecodeSourceToSequence
to receive a flow rather than blocking until the entire source is serialized? For context, I'm receiving a response with a ktor client using http streamingS.
12/18/2024, 6:21 PMchannelFlow<ExerciseList.Exercise> {
client.prepareGet("<http://localhost:8080/list>").execute { httpResponse ->
val channel: ByteReadChannel = httpResponse.body()
while (!channel.isClosedForRead) {
channel.readAvailable(10) {
trySend(
Serializer.json.decodeFromString(
it.readString().drop(1).dropLastWhile { it == ']' })
)
0
}
}
}
}.collect {
println(it)
}
S.
12/18/2024, 6:21 PMJaap Beetstra
12/18/2024, 6:22 PMval deserializer: DeserializationStrategy<Unit> = buildDeserializer {
field("description") { description: Text -> showText(description) }
objectField("table") {
arrayField("columnNames") { name: String -> addColumnName(name) }
arrayField("rows") { row: Row -> processRow(row) }
}
}
Json.decodeFromStream(deserializer, FileInputStream("huge-table.json"))
That deserializer could then be used to decode a Json object like this:
{ "description":"text...",
"table": {
"columnNames":["a","b",c"],
"rows": [ { row 1 }, { row 2 } ]
}
}
Where Row
is just a standard @Serializable
class.
You can find it on maven: implementation("com.beetstra.blockbuster:blockbuster:0.1.0")
Is that what you are looking for?S.
12/18/2024, 6:26 PMS.
12/18/2024, 7:43 PM