Any elegant work around for ObjectId emulation class for GWT module ?- issue 103

117 views
Skip to first unread message

Yves

unread,
Oct 12, 2010, 10:20:33 AM10/12/10
to Morphia
Hi guys,

just wondering if anybody can suggest an elegant work around for
emulating ObjectId for GWT module at the moment. (issue 103
http://code.google.com/p/morphia/issues/detail?id=103)

Hoping this will be fixed. Keep up the great work Morphia!


-
yves

Joel

unread,
Oct 12, 2010, 3:49:08 PM10/12/10
to Morphia
I just created simple emulation with the following two classes below.
It doesn't have the functionality of a real ObjectId (e.g. no
getTime()) but it allowed me to pass my objects via RPC. I found the
documentation on how to emulate classes a bit lacking but this page
http://code.google.com/p/wogwt/wiki/CustomFieldSerializer
was helpful as well as looking at the source from this project
http://code.google.com/p/gwtx/



package org.bson.types;

import com.google.gwt.user.client.rpc.SerializationException;
import com.google.gwt.user.client.rpc.SerializationStreamReader;
import com.google.gwt.user.client.rpc.SerializationStreamWriter;

public final class ObjectId_CustomFieldSerializer {

public static void deserialize(SerializationStreamReader
streamReader, ObjectId instance)
throws SerializationException {

}

public static ObjectId instantiate(SerializationStreamReader
streamReader)
throws SerializationException {
String id = streamReader.readString();
return new ObjectId(id);
}

public static void serialize(SerializationStreamWriter streamWriter,
ObjectId instance)
throws SerializationException {
streamWriter.writeString(instance.toString());
}

}

package org.bson.types;

public class ObjectId implements java.io.Serializable {

final String id;

public ObjectId(String id) {
this.id = id;
}

public String toString() {
return id;
}
}

On Oct 12, 10:20 am, Yves <yveshw...@gmail.com> wrote:
> Hi guys,
>
> just wondering if anybody can suggest an elegant work around for
> emulating ObjectId for GWT module at the moment. (issue 103http://code.google.com/p/morphia/issues/detail?id=103)

Scott Hernandez

unread,
Oct 12, 2010, 3:55:14 PM10/12/10
to mor...@googlegroups.com
Yep, that is basically what we will do in morphia as a module for gwt.
We may expose some of the other methods to get the time and components
of ObjectId.

Yves

unread,
Oct 13, 2010, 11:38:26 AM10/13/10
to Morphia
fantastic! it is quite elegant indeed. I have followed exactly as you
have mentioned and it works seamlessly with our whole architectural
stack. Thanks Joel and Scott!



On Oct 12, 9:55 pm, Scott Hernandez <scotthernan...@gmail.com> wrote:
> Yep, that is basically what we will do in morphia as a module for gwt.
> We may expose some of the other methods to get the time and components
> of ObjectId.
>

thoma.b...@parislabs.net

unread,
Mar 15, 2018, 9:40:23 AM3/15/18
to Morphia
Hi, 

Sorry to dig this up, but I am trying to implement the emulator for ObjectId class. 
I just have a question, I have seen that you are adding the new classes to the package org.bson.types, but when I try to add it as the package is read only I cannot add them there. 
Do you have any clue on how to implement the serialization without the emulator being in the same package ? 

Thank you. 
Thoma
Reply all
Reply to author
Forward
0 new messages