https://kotlinlang.org logo
Title
g

gildor

07/17/2018, 3:22 PM
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

dave08

07/17/2018, 3:25 PM
Nope, I need two stages because I don't know to what type I'll be parsing the
result
at this stage...
g

gildor

07/17/2018, 3:27 PM
But why? you should know result type, because you know request type
c

cedric

07/17/2018, 3:28 PM
It's pretty common to have two stages of parsing, I remember the Facebook API having a lot of that
g

gildor

07/17/2018, 3:31 PM
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

cedric

07/17/2018, 3:31 PM
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

gildor

07/17/2018, 3:32 PM
Yeah, sure. Just curious. Because it’s so common case
d

dave08

07/17/2018, 3:34 PM
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
...?