[JAVA-111] JSON.parse() and serialize() do not preserve the _id field across serializations as expected Created: 26/Apr/10 Updated: 29/Oct/10 Resolved: 25/May/10 |
|
| Status: | Closed |
| Project: | Java Driver |
| Component/s: | None |
| Affects Version/s: | None |
| Fix Version/s: | 2.0 |
| Type: | Improvement | Priority: | Major - P3 |
| Reporter: | William Shulman | Assignee: | Eliot Horowitz (Inactive) |
| Resolution: | Done | Votes: | 0 |
| Labels: | None | ||
| Remaining Estimate: | Not Specified | ||
| Time Spent: | Not Specified | ||
| Original Estimate: | Not Specified | ||
| Description |
|
The current behavior might be intended, but it seems that the JSON utility class does not properly handle ObjectIds when serializing and parsing. I would expect that creating a DBObject (and saving to generate an ObjectId), serializing it, and then parsing would result in a new DBObject instance with the same _id as the original. That is, I would expect that parse(serialize(o)).id to equal o.id. This is not the case. The following code illustrates the problem: DBCollection c = getMeACollection(); // clear the collection DBObject o = new BasicDBObject(); results in two documents in the collection (I would expect one): { "_id" : ObjectId("4bd62964037394994a295cd3") } { "_id" : "4bd62964037394994a295cd3" }
|
| Comments |
| Comment by William Shulman [ 25/May/10 ] |
|
This can be closed now. Made changes to the Java driver to fix this |
| Comment by William Shulman [ 27/Apr/10 ] |
|
Looks related to More generally it is probably an issue for most drivers. |