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

deserializing a Set requires elements to implement Comparable, when ordering is not required #100

Closed
GoogleCodeExporter opened this issue Mar 19, 2015 · 5 comments

Comments

@GoogleCodeExporter
Copy link

What steps will reproduce the problem?
1. See attached beans Tree and Monkey
2. Run this test:

    Tree tree = new Tree();
    tree.getMonkeys().add(new Monkey());
    tree.getMonkeys().add(new Monkey());

    String serialised = json.toJson(tree);
    Tree newTree = json.fromJson(serialised, Tree.class);

What is the expected output? What do you see instead?

Deserialize fails, Caused by: java.lang.ClassCastException:
com.jpmorgan.ibmlbus.beans.serialise.Monkey cannot be cast to
java.lang.Comparable
    at java.util.TreeMap.put(Unknown Source)
    at java.util.TreeSet.add(Unknown Source)
    at
com.google.gson.DefaultTypeAdapters$CollectionTypeAdapter.deserialize(DefaultTyp
eAdapters.java:404)
    at
com.google.gson.DefaultTypeAdapters$CollectionTypeAdapter.deserialize(DefaultTyp
eAdapters.java:369)
    at
com.google.gson.JsonDeserializerExceptionWrapper.deserialize(JsonDeserializerExc
eptionWrapper.java:50)
    ... 27 more

The point is that Monkeys have no natural ordering. We should be able to
use them in a Set though, because uniqueness is fine.

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

Please provide any additional information below.


Original issue reported on code.google.com by aaron.b...@gmail.com on 12 Feb 2009 at 4:08

Attachments:

@GoogleCodeExporter
Copy link
Author

Hi - could you please delete the package names from the attached beans? My 
error.

Original comment by aaron.b...@gmail.com on 12 Feb 2009 at 4:22

@GoogleCodeExporter
Copy link
Author

Sorry, I do not have the ability to edit the original bug report. 

Original comment by inder123 on 12 Mar 2009 at 2:00

@GoogleCodeExporter
Copy link
Author

Fixed this bug in r394 by using HashSet instead of TreeSet while instantiating 
sets
during deserialization

Original comment by inder123 on 12 Mar 2009 at 2:00

  • Changed state: Fixed

@GoogleCodeExporter
Copy link
Author

Updated in r395 to ensure that sorted sets continue to use TreeSets and HashSet 
is
used for other sets.

Original comment by inder123 on 12 Mar 2009 at 6:17

@GoogleCodeExporter
Copy link
Author

Original comment by inder123 on 27 Mar 2009 at 7:39

  • Added labels: Milestone-Release1.3

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