-
Notifications
You must be signed in to change notification settings - Fork 2.6k
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
Handling of null-values in JSONObject and XML.toString() #429
Comments
No, in this case it's working as designed. In Javascript and JSON, null is a value (as opposed to undefined). In order to maintain the JSON value of null when converting to XML we output that as the string "null". |
Thanks for your quick reply. So in our case there is no difference in the xml for the input
Do you have a suggestion how we can get our expected output? |
hmm, now that I'm looking at the code and the history of it, this may be a bug. At https://github.com/stleary/JSON-java/blob/master/XML.java#L594 you can see a null check for the value. This is the java In reality, the null check in the @stleary Let me know your opinion on this. It may be a small tweak we want to make. |
@johnjaylward thanks for investigating. Are you suggesting adding a check for JSON null or replacing the existing check? |
Replacing the existing check with |
Sounds reasonable, no objection on this end. |
fixes stleary#429. Updates JSON-> XML conversion to treat all NULL types the same. Previously a JSONObject having a key with a JSONObject.NULL value would output `<key>null</key>`. However, a JSONObject having a key with a value of JAVA `null` would output as `<key />`. This change unifies the output so both now output as `<key />`.
Thanks, you two. My pull-request would have looked exactly like yours, johnjaylward. I'm looking forward to the upcomming release. |
I'm still updating it a little due to test failures since we were validating that functionality |
Hi, It may be a new attribute |
@javadev We added a workaround in our code. We replace all |
I saw the pull-request #412 for another feature request. Can you imagine to also make the output configurable by an additional parameter to the |
It may be converter to xml like this: <?xml version="1.0" encoding="UTF-8"?>
<root>
<myKey null="true"/>
<myKey2>null</myKey2>
</root> |
#412 is a good idea. I will proceed with integrating with the unit tests and getting it committed. A section has been added to the Wiki FAQ that addresses how XML requests will be handled going forward. |
We have a json-string and want to convert it to a corresponding xml-string. In case, that there are null-values in the json-string, we get an unexpected result
JSon-String
What we do
What we get
<myKey>null</myKey>
What we expect
<myKey/>
Is our expectation correct? If yes, I would do a pull-request and change line 594 in class
XML.java
The text was updated successfully, but these errors were encountered: