javadev / underscore-java

java port of Underscore.js
https://javadev.github.io/underscore-java/
MIT License
533 stars 80 forks source link

How to replace null value with empty when use U.jsonToXml() #285

Closed dejavuhuh closed 3 years ago

dejavuhuh commented 3 years ago

When I convert xml to json, I can use U.xmlToJson(xml, U.Mode.REPLACE_EMPTY_VALUE_WITH_NULL) but when I convert json to xml, there is no way to replace null value with empty like U.jsonToXml(json, U.Mode.REPLACE_NULL_VALUE_WITH_EMPTY) This brings some problems, for example, there is a xml content like below

<aaa>
    <bbb></bbb>
</aaa>

when I convert it to json

String xml = "<aaa><bbb></bbb></aaa>"
String json = U.xmlToJson(xml, U.Mode.REPLACE_EMPTY_VALUE_WITH_NULL);

the json result is

{
    "aaa": {
        "bbb": null
    }
}

but, when I convert the json result to xml

String xml = U.jsonToXml(json);

the xml result is

<aaa>
    <bbb null="true"/>
</aaa>

But this is not what i want

javadev commented 3 years ago

Thank you for the issue. I added a new mode REPLACE_NULL_WITH_EMPTY_VALUE to the U.jsonToXml() method.

dejavuhuh commented 3 years ago

thanks very much!

javadev commented 3 years ago

The new version library was released today. 🎉