Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

JSON parser converts null values to the string "null" #3

Closed
GoogleCodeExporter opened this issue Sep 5, 2015 · 6 comments
Closed

Comments

@GoogleCodeExporter
Copy link

What steps will reproduce the problem?
1. Create a JSON string where one of the fields' values is null.
2. Use ProtobufJSON.parseFrom() to parse the string.
3. In the resulting Protobuf object, the field will contain the literal
string "null".

The expected result is for the field to have the Java null value.

The attached patch corrects this behavior. (And it eliminates an extra
semicolon that causes compiler warnings.)

Original issue reported on code.google.com by oren.hur...@gmail.com on 23 Jan 2010 at 7:09

Attachments:

@GoogleCodeExporter
Copy link
Author

Sorry for being so late. I forgot to setup notifications on the issues :/

Original comment by david.yu...@gmail.com on 6 Mar 2010 at 4:58

@GoogleCodeExporter
Copy link
Author

This seems to be a problem for other nullable values as well ... not just 
strings.
Plus, the Message.Builder will throw an NPE if the string you set is null.
We could call clearFoo() instead if the string is null.
I've modified the patch (fixnull2.patch)

Let me know what you think.

Thanks.



Original comment by david.yu...@gmail.com on 6 Mar 2010 at 7:15

Attachments:

@GoogleCodeExporter
Copy link
Author

You're right that in Protobuf we shouldn't be setting fields to Null, but rather
avoid setting them at all. I submitted this issue a while back, so I no longer
remember if I encountered this problem because of a bug on my part or something 
more
substantial. I would go with your patch.

Original comment by oren.hur...@gmail.com on 6 Mar 2010 at 8:11

@GoogleCodeExporter
Copy link
Author

Protobuf's native parsing does not have logic for clearing fields upon 
deserialization.
Because of its built-in default-values and required-values support, only fields 
that
are specifically set (null/default values aren't written) are the only ones 
included
on serialization.

In short, protobuf doesn't pass null values around ... 
The logic to explicitly set/clear the values is handled by application code.

Thanks for the report though!  Gave me a lot of thinking to do.


Original comment by david.yu...@gmail.com on 9 Mar 2010 at 3:21

  • Changed state: WontFix

@GoogleCodeExporter
Copy link
Author

A clear method will prolly have to be added on the gwt-overlay code to clear a
property so it won't be included on serialization.

See http://code.google.com/p/protostuff/issues/detail?id=7

Original comment by david.yu...@gmail.com on 9 Mar 2010 at 3:28

@GoogleCodeExporter
Copy link
Author

Looking back at this issue ... I do think this still need to be addressed since
messages with "null" values are unacceptable.

Also jackson's parser converts int values to String if calling getText()

The fix is strictly allowing only the token: JsonToken.VALUE_STRING.
New patch attached/applied (rev 678)

Original comment by david.yu...@gmail.com on 7 May 2010 at 3:42

  • Changed state: Fixed

Attachments:

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant