Abedeljalil / json-simple

Automatically exported from code.google.com/p/json-simple
Apache License 2.0
0 stars 0 forks source link

linkedHashMap does not preserve order once data has reached client #89

Open GoogleCodeExporter opened 8 years ago

GoogleCodeExporter commented 8 years ago
What steps will reproduce the problem?

1. put key value in linkedHashMap in a specific order
2. output json data on client in ajax response
3. order is not preserved

Map<String, String> obj=new LinkedHashMap<String, String>();
for (String id : runTimes.keySet()) {
    obj.put(id, runTimes.get(id));
}
String jsonString = JSONValue.toJSONString(obj);

resp.setContentType("application/json; charset=utf-8");
PrintWriter out = resp.getWriter();
log.debug("pricing runtimes json: " +jsonString );
out.println(jsonString );
out.flush();
out.close();

expected:
pricing runtimes json: {"19":"09\/05\/2013 02:55 PM","18":"09\/05\/2013 02:09 
PM","16":"08\/29\/2013 02:49 PM"}

What is the expected output? What do you see instead?
The order is out put correctly in java but when the json data is returned to 
the client, the order has been resorted.

in ajax response:
Object {16: "08/29/2013 02:49 PM", 18: "09/05/2013 02:09 PM", 19: "09/05/2013 
02:55 PM"}

What version of the product are you using? On what operating system?

Please provide any additional information below.

Original issue reported on code.google.com by multispe...@gmail.com on 16 Sep 2013 at 12:26