Issue 384 in morphia: TypeConverter ignored for referenced member

0 views
Skip to first unread message

mor...@googlecode.com

unread,
Feb 27, 2012, 3:23:11 PM2/27/12
to morphia...@googlegroups.com
Status: New
Owner: ----
Labels: Type-Defect Priority-Low

New issue 384 by ones...@gmail.com: TypeConverter ignored for referenced
member
http://code.google.com/p/morphia/issues/detail?id=384


I define a TypeConverter like this :

morphia.getMapper().getConverters().addConverter( new IDConverter() );

and yet my class User, referenced Client, has an ID member that is not
being converted -- even though the member of the User class is converted
properly. So the converter seems to be ignored in the referenced class.

@Entity
public class User {
@Id
ID id;
@Reference
IClient client;
}

@Entity
public class Client {
@Id
ID id;
}

========

java.lang.IllegalArgumentException: can't serialize class ID
at org.bson.BasicBSONEncoder._putObjectField(BasicBSONEncoder.java:234)
at org.bson.BasicBSONEncoder.putObject(BasicBSONEncoder.java:140)
at org.bson.BasicBSONEncoder._putObjectField(BasicBSONEncoder.java:224)
at org.bson.BasicBSONEncoder.putObject(BasicBSONEncoder.java:140)
at org.bson.BasicBSONEncoder.putObject(BasicBSONEncoder.java:86)
at com.mongodb.DefaultDBEncoder.writeObject(DefaultDBEncoder.java:27)
at com.mongodb.OutMessage.putObject(OutMessage.java:142)
at com.mongodb.DBApiLayer$MyCollection.update(DBApiLayer.java:346)
at com.mongodb.DBCollection.update(DBCollection.java:165)
at com.mongodb.DBCollection.save(DBCollection.java:724)
at com.google.code.morphia.DatastoreImpl.save(DatastoreImpl.java:731)
at com.google.code.morphia.DatastoreImpl.save(DatastoreImpl.java:793)
at com.google.code.morphia.DatastoreImpl.save(DatastoreImpl.java:787)


========

The IDConverter works fine - if I mark the client as @Transient.

Here is the decode method :

@Override
public Object decode(final Class targetClass, final Object
fromDBObject, final MappedField optionalExtraInfo) throws MappingException {
return new ID((String) fromDBObject);
}


Reply all
Reply to author
Forward
0 new messages