You always can have 2 stages of parsing
# klaxon
g
You always can have 2 stages of parsing
🤔 1
@dave08 I mean parse once, just to detect which of them is not null, then parse again as error/result
d
Nope, I need two stages because I don't know to what type I'll be parsing the
result
at this stage...
g
But why? you should know result type, because you know request type
c
It's pretty common to have two stages of parsing, I remember the Facebook API having a lot of that
g
Cedric, but on your experience, what would be more efficient: 1. parse result to string/any 2. parse it to something like Gson’s JsonObject, so it can be faster to map this later to a class?
c
My experience is not a reliable benchmark 🙂
Measure.
But overall, I wouldn't worry too much, these extra JSON payloads are usually not that big
but you can probably get fancy with the streaming API if you want to avoid overhead
read each field as it comes, wait for the type one, then you know how to parse the string when it comes in
g
Yeah, sure. Just curious. Because it’s so common case
d
But it might still be practical to have a rawJsonString property in JsonValue? Or is there already? That way a field converter could be made for this...
My payloads are requests that could potentially retrieve an array of lots of objects... it might be nice to avoid the extra step. The streaming doesn't help, since my JsonRpc client is seperate from the one actually parsing the payloads...
So I won't know the type yet...
So so far it's either using JsonValue type for
result
...?