[JAVA-700] Cannot Serialize/Deserialize ObjectId using Adobe BlazeDS(flex-messaging) Created: 22/Nov/12 Updated: 25/Jun/13 Resolved: 25/Nov/12 |
|
| Status: | Closed |
| Project: | Java Driver |
| Component/s: | API, Codecs |
| Affects Version/s: | 2.9.1, 2.9.2, 2.9.3 |
| Fix Version/s: | None |
| Type: | Bug | Priority: | Major - P3 |
| Reporter: | Daniel Marcotte | Assignee: | Unassigned |
| Resolution: | Done | Votes: | 1 |
| Labels: | ObjectId, adobe, blazeds, deserialization, driver, serialization | ||
| Remaining Estimate: | Not Specified | ||
| Time Spent: | Not Specified | ||
| Original Estimate: | Not Specified | ||
| Environment: |
Windows 2008 Server |
||
| Attachments: |
|
| Description |
|
Hello, I use Native Adobe BlazeDS Library used to serialize and deserialize AMF (Action Message Format) which can convert native ActionScript3/Flex objects to Java Objects. This serialization library looks for "public" non-transient fields in the object, recursively and transform them from AS/Java | Java/As. However, in the ObjectId class, the "_inc", "_time" and "_machine" fields are using default access modifiers and are "final int". In the ObjectId default constructor a new ID is generated : Doing so, BlazeDS creates a new ObjectId on deserialization and cannot modifier furthermore the "final int". The ObjectId is a new one. ********************************************************** I've modified your ObjectId class and rebuilt it with "public int _inc" instead of "final int _inc" and it now works properly. However, I understand that it breaks your class encapsulation. ********************************************************** I would like to know if you plan on something regarding this class. Would it be possible to : 1 - make fields public instead of package-protected final? I've attached a demo with the native library and the modified one. Thanks for your time. Daniel Marcotte |
| Comments |
| Comment by Jeffrey Yemin [ 23/Nov/12 ] |
|
Hi Daniel, I definitely want to leave the ObjectId class immutable, which means that all fields are final and need to be initialized in every constructor. This insures that ObjectId instances are thread-safe and don't require any further synchronization. I think your best bet is to something like option 3 in the description. Just make sure that you don't try to insert instances of ObjectId2 into Mongo. You'll have to convert to ObjectId before insertion. |