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

XML transformation after send JSON element with null value is not being generated correctly #129

Closed
asalgav opened this issue Jun 3, 2015 · 3 comments

Comments

@asalgav
Copy link

asalgav commented Jun 3, 2015

Hi,

I believe XML class needs to consider that, on cases where a Json code like below is sent:
{
"test":
{ "child": null }
}
is currently being converted as:

<test>
<child>null</child>
</test>

rather than:

<test>
<child/>
</test>

And this is due to an if structure made on the line 408 (XML.java). This comparison needs to be overriding by equals() method. Otherwise, it compares by references:

XML.toString(Object object, String tagName) {
... 
 /*value is type JSONObject*/ 
value = jo.opt(key);
/*408*/ if (value == null) {
                 value = "";
            }

I suggest something like value.equals(null) and the problem would be fixed.

Regards

@johnjaylward
Copy link
Contributor

looks like your XML example got stripped by the markdown. can you edit?

@asalgav
Copy link
Author

asalgav commented Jun 3, 2015

Sorry, I missed that.
Thank you for your very quick response.

@stleary
Copy link
Owner

stleary commented Jun 6, 2015

Inclined to agree that this may be a bug. The toString() output would be correct in a JSON doc, but maybe not so much in an XML doc. However, there are a couple of problems:

  • Why is the proposed solution the best choice, given that XML does not support null (as far as I know)?
  • I think the analysis may be incomplete. For example, the Javadoc for JSONObject.opt(key) says that it may return null. Perhaps that is the purpose of line 408.

Can't proceed with this issue as it is currently stated, but feel free to resubmit after addressing the above items.

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

No branches or pull requests

3 participants