title: How to convert XML to JSON in Java and avoid the parser to attempt parsing String as numbers
body: <p>I'm using org.json.XML library to parse XML to JSON. <a href="http://www.json.org/javadoc/org/json/XML.html" rel="nofollow">http://www.json.org/javadoc/org/json/XML.html</a></p>
  
  <p>In my XML doc there is an ID field that is randomly generated with [0-9][a-z]. It is intended to be a String. Everything works fine until there's this unlucky ID 123456789e1234 that happens to be a scientific notation of a number.
  Here's a piece of test code:</p>
  
  <pre><code>public class XmlToJsonTest {
      public static String testXML = "&lt;MyXML&gt;&lt;ID&gt;123456789e1234&lt;/ID&gt;&lt;/MyXML&gt;";
      @Test
      public void testXMLtoJSON() throws JSONException {
          JSONObject testJsonObject = XML.toJSONObject(testXML);
      }
  }
  </code></pre>
  
  <p>Here's the exception: </p>
  
  <pre><code>org.json.JSONException: JSON does not allow non-finite numbers.
  </code></pre>
  
  <p>The XML lib toJson() method first attempts to converts the String to Integer, Long or Double and if none works, it gives up parsing it as number and treats it like a String. In this case the String 123456789e1234 is parsable as a Double. And later when the lib checks if the double is infinite by Double.isInfinite(), it throws the JSONException since obviously 123456789e1234 is greater than Double's standard of finite.</p>
  
  <p>How do I force it not to parse the value as number at all? Is there any java library out there that correctly converts XML to JSON in this case?</p>