Search code examples
javajsonxmljson-lib

Avoid e-notation using net.sf.json-lib


I'm using com.hynnet.json-lib to convert XML to JSON. PB here is that for long integers this library use exponents instead of full-number.

Could I avoid it using this library or should I use another one?

My XML:

<?xml version="1.0" encoding="ISO-8859-15"?>
<rootTag>
    <_id type="number">7000000001</_id>
</rootTag>

My convertion-code:

XMLSerializer xmlSerializer = new XMLSerializer();
xmlSerializer.clearNamespaces();
xmlSerializer.setSkipNamespaces(true);
xmlSerializer.setForceTopLevelObject(false);
net.sf.json.JSON json = xmlSerializer.read(xmlString);

Result json:

{"_id": 7.000000001E9}

Expected json:

{"_id": 7000000001}


Solution

  • enter image description here

    Found the reason of such behavior. Double.valueof(String) returns exponential view. Bug on library's side.