staxon icon indicating copy to clipboard operation
staxon copied to clipboard

JSON to XML to JSON conversion when primitive types are in the JSON

Open riyafa opened this issue 7 years ago • 0 comments

This is another use case of converting JSON to XML and then the same XML to JSON

Suppose I have the following JSON:

{
    "a": {
        "hello": "world",
        "some": "1",
        "yes": 2,
        "Value": "PartyId"
    }
}

The JSON to XML conversion yields the following:

<?xml version="1.0" ?>
<a>
	<hello>world</hello>
	<some>1</some>
	<yes>2</yes>
	<Value>PartyId</Value>
</a>

When PROP_AUTO_PRIMITIVE is set to true the above XML to JSON conversion yields the following:

{
	"a" : {
		"hello" : "world",
		"some" : 1,
		"yes" : 2,
		"Value" : "PartyId"
	}
}

When PROP_AUTO_PRIMITIVE is set to false following is obtained:

{
	"a" : {
		"hello" : "world",
		"some" : "1",
		"yes" : "2",
		"Value" : "PartyId"
	}
}

In both cases I am unable to obtain the initial input. Is it possible to obtain the initial input if we do conversions like the above? My use case is where I get a JSON as input then I convert it to XML and do some processing and then convert it back to JSON as output. I cannot get the original JSON input when I do this conversions because there are no convention for primitive type to xml conversion. It is converted the same as when a double quoted string is in the value. Can we achieve this without changing the mapping convention? Or if we do change how can we do it so that I can also try to contribute to achieve this?

riyafa avatar Jan 24 '18 03:01 riyafa