Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

JSONArray is deserialized to ArryList #18

Closed
GoogleCodeExporter opened this issue Sep 10, 2015 · 7 comments
Closed

JSONArray is deserialized to ArryList #18

GoogleCodeExporter opened this issue Sep 10, 2015 · 7 comments

Comments

@GoogleCodeExporter
Copy link

I use your excellent library in Android project. I run into issue where if I 
try to pass JSONArray to the Activity by doing Intent.putExtra(String key, 
Serializable array) when I try to retrieve that array doing 
Intent.getSeriaizableExtra(key, null) array is converted to the plain 
ArrayList. Not only that but all the nested JSONObjects are converted to 
HashMaps. Currently I go around this by dumping content of JSONArray to String 
and then recreating it. However that is quite memory intensive especially for 
larger data sets. 
Anything you would recommend?

Regards,

Bo Stone

Original issue reported on code.google.com by bost...@gmail.com on 12 Nov 2011 at 7:27

@GoogleCodeExporter
Copy link
Author

Please can you send me a sample project showing the trouble.

Uriel.

Original comment by uriel.chemouni on 14 Nov 2011 at 9:52

@GoogleCodeExporter
Copy link
Author

Sample Android project is attached. Import into Eclipse and run (you will need 
Google Android plugin). You will see that the original JSONObject is converted 
to plain HashMap during deserialization.

Just to note - this seems to be Android-related problem since the code below 
does everything properly

[code]
JSONObject original = (JSONObject) 
JSONValue.parse("{one:1,two:[three:3,four:4,five:'five']}");
        try {
            // serialize
            ByteArrayOutputStream out = new ByteArrayOutputStream();
            ObjectOutputStream oos = new ObjectOutputStream(out);
            oos.writeObject(original);
            oos.close();
            // deserialize
            byte[] pickled = out.toByteArray();
            InputStream in = new ByteArrayInputStream(pickled);
            ObjectInputStream ois = new ObjectInputStream(in); 
            Object o = ois.readObject();
            System.out.println("Got: " + o + ", with class type of " + (o == null ? null : o.getClass())); 
        } catch (IOException e) {
            e.printStackTrace();
        } catch (ClassNotFoundException e) {
            e.printStackTrace();
        }
[/code]

Original comment by bost...@gmail.com on 14 Nov 2011 at 8:38

@GoogleCodeExporter
Copy link
Author

your json message look to be invalide.

"{one:1,two:[three:3,four:4,five:'five']}"
should probably be replaced by:
"{one:1,two:{three:3,four:4,five:'five'}}"
or
"{one:1,two:{three:3,four:4,five:five}}"
or
"{'one':1,'two':{'three':3,'four':4,'five':'five'}}"

Original comment by uriel.chemouni on 15 Nov 2011 at 10:51

@GoogleCodeExporter
Copy link
Author

Why? Two is JSON array. It parses just fine, I don't think that is the issue

Original comment by bost...@gmail.com on 15 Nov 2011 at 11:00

@GoogleCodeExporter
Copy link
Author

if you want 'two' to be an array use :
"{'one':1,'two':['three',3,'four',4,'five','five']}"
or 
"{one:1,two:[three,3,four,4,five,five]}"




Original comment by uriel.chemouni on 15 Nov 2011 at 11:58

  • Changed state: Done
  • Added labels: Type-Review
  • Removed labels: Type-Defect

@GoogleCodeExporter
Copy link
Author

I noticed that you closed this bug - has this been resolved? Can I get a patch?

Original comment by bost...@gmail.com on 19 Nov 2011 at 9:44

@GoogleCodeExporter
Copy link
Author

Cross reference to posting on Stackoverflow.com http://goo.gl/CVw1U

Original comment by bost...@gmail.com on 9 Dec 2011 at 7:39

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant