Package eu.vstoyanov.natsy.codec
Class JsonCodec
-
- All Implemented Interfaces:
-
eu.vstoyanov.natsy.codec.MessageCodec
public final class JsonCodec<T extends Object> implements MessageCodec<T>
Carries a value as UTF-8 JSON via kotlinx.serialization.
This is what CodecRegistry derives for any
@Serializabletype, so it rarely needs to be constructed by hand - do so to give one type a Json of its own:codecs { register(JsonCodec(Report.serializer(), Json(JsonCodec.defaults) { prettyPrint = true })) }Starting that Json from defaults rather than from kotlinx's own is what keeps the one type behaving like every other: Json has no notion of "inherit the rest", so a bare
Json { prettyPrint = true }quietly opts the type out of tolerating unknown keys, and the producer that adds a field stops this consumer instead of the two carrying on apart.
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description public classJsonCodec.Companion
-
Field Summary
Fields Modifier and Type Field Description private final StringcontentTypepublic final static JsonCodec.CompanionCompanion
-