pvdung / quick-json

Automatically exported from code.google.com/p/quick-json
0 stars 0 forks source link

Parsing same json line with re-used parser results in different root #12

Open GoogleCodeExporter opened 9 years ago

GoogleCodeExporter commented 9 years ago
What steps will reproduce the problem?
1. Create the following java object

public class TestClass {
    private JsonParserFactory factory=JsonParserFactory.getInstance();
    private JSONParser parser=factory.newJsonParser();

    public void test() {
        Map jsonData=parser.parseJson("[{"url":"http://test1234.com"}]");
        ArrayList rootJson;
        String url;
        try {
            rootJson=(ArrayList)jsonData.get("root");
            url=(String)((Map)rootJson.get(0)).get("url");
System.out.println("Output root: "+url);
        } catch(Exception exp) {
            rootJson=(ArrayList)jsonData.get("urlroot");
            url=(String)((Map)rootJson.get(0)).get("url");
System.out.println("Output urlroot: "+url);         
        }
    }
}

2. Run the test line: 
TestClass testClass=new TestClass();
testClass.test();
testClass.test();

3. Result 1:
Output root: http://test1234.com
Result 2:
Output urlroot: http://test1234.com

What is the expected output? What do you see instead?
Expected is just result 1 (the clean result) in both runs.

What version of the product are you using? On what operating system?
quick-json-1.0.2.3.jar

Please provide any additional information below.
Problem is only replicated when using parser as indicated since the parser is 
only instantiated once (high thread re-use). Problem is very hard to trace 
since the result is totally unexpected (works once, why not twice the same). 

Original issue reported on code.google.com by norb...@vnitconsultancy.nl on 2 Mar 2015 at 7:35