peter-oziegbe / json-simple

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

Order of elements not preserved. #80

Closed GoogleCodeExporter closed 8 years ago

GoogleCodeExporter commented 8 years ago
What steps will reproduce the problem?
1. Create LinkedHashMap, add some stuff to it
2. Create JSONObject, add some stuff to it
3. Generate json.

What is the expected output? What do you see instead?
Elements are unordered. Problem lies in design of JSONObject - it extends 
java.util.HashMap. Javadoc comment states that key-value pairs are unordered, 
while documentation suggests otherwise.

What version of the product are you using? On what operating system?
json-simple-1.1.1.jar, Oracle JDK1.6.0_31 32-bit, Windows 8 Pro x64. 

Please provide any additional information below.
JSONObject.toJSONString( map ) works as expected.

Original issue reported on code.google.com by marko.ta...@gmail.com on 16 Dec 2012 at 9:11

Attachments:

GoogleCodeExporter commented 8 years ago
It's addressed in the wiki:
http://code.google.com/p/json-simple/wiki/EncodingExamples#Example_1-1_-_Encode_
a_JSON_object

Is it misleading?

Original comment by fangyid...@gmail.com on 18 Dec 2012 at 7:53

GoogleCodeExporter commented 8 years ago
Yeah..  It is misleading..

I read that paragraph before opening this issue and what I understood from it 
was this:
"Ordering of JSONObject elements is determined by provided map implementation. 
java.util.HashMap is default, but you can chose/pass any other map."

What was actually stated there is this:
JSONObject is subclass of java.util.HashMap. No ordering is provided. If you 
need strict ordering of elements use JSONValue.toJSONString( map ) method.

Original comment by marko.ta...@gmail.com on 18 Dec 2012 at 8:33

GoogleCodeExporter commented 8 years ago
Thank you for your suggestion! I've modified the wiki page.

Original comment by fangyid...@gmail.com on 20 Dec 2012 at 2:13

GoogleCodeExporter commented 8 years ago
Cool! Glad to help..

Thank you on your work.

Original comment by marko.ta...@gmail.com on 20 Dec 2012 at 1:58