-
Notifications
You must be signed in to change notification settings - Fork 119
Parsing null in array fails for JValue #41
Comments
Coda answered this one for me today… Just use: The result will then be Simple when you know how! :)
|
Sorry, but this doesn't work on 0.5.0 and it doesn't make much sense- is this supposed to also handle nulls in any nested arrays? Even if it worked, why would you get null for anything which is declared to be an Option? Shouldn't it be None? |
If you mean this answer: To give more context: of course it would work with The way I see it, JValue could be anything, and if |
Apologies, I was in too much of a rush last night that I didn't test my example and also typed Please note that these comments below represent my understanding of what happens and (at least for me) a workable solution but clearly, in time, it would be good if Jerkson made these things work better. So, let's get it right this time. First of all the preamble:
Okay, as you say
produces:
I thought this should work as I thought
The result is:
So a null on its own does have a JValue representation and parses correctly. Now, Coda's tweet: https://twitter.com/coda/status/141959832570834944 prompted me to try:
But unfortunately this doesn't work either, giving effectively the same error:
However, if you are in a position to anticipate the top level collection of the object you are parsing. And in working cases this is true, then you can enter:
So, here we are saying that we expect a list of anything which may also contain nulls ( - e.g. they are optional). And the result is:
which feels like progress. And it does, to some extent allow for completely unknown JSON hierarchies. For example:
correctly returns:
However, you always have to be on the lookout for nulls which, if not anticipated by an explicit
Which results in:
|
Thanks, Stuart, this explains it better than I did. As you mentioned, this workaround is not a general solution, since "you always have to be on the lookout for nulls". |
parse[JValue]("""[null]""")
produces"Can not deserialize instance of com.codahale.jerkson.AST$JValue out of VALUE_NULL token"
at ... blablabla
The text was updated successfully, but these errors were encountered: