Can't a `KSerializer` do some look-ahead for the n...
# serialization
m
Can't a
KSerializer
do some look-ahead for the next token type when reading something? E.g. • if next token is string then decode as A • if next token is object then decode as B
s
In general – no (some formats don't support this). If you know which
decoder
you use in advance, you can downcast to it in
deserialize
m
A the moment I'm using
decodeString
guarded with a try catch and upon exception I try to decode an object instead. Do you happen to have an example for a format which doesn't know the type of the current token/value?
Btw even the json decoder doesn't let me peek at the next type
s
E.g. protobuf have the same 'wire type' for strings/objects/bytearrays
🤔 1
JsonInput have method
decodeJson
which allows to consume current node of the tree (primitive/array/object)
m
Yeah I don't want to fully decode it into a JsonElement though but continue with stream & decoder based parsing. I need to parse the object somehow with other serializers :)