New issue 377 by sylvain.wallez: @Serialized doesn't work with runtime
values of primitive types
http://code.google.com/p/morphia/issues/detail?id=377
morphia-0.99 / driver 2.7.2 / mongo 2.0.1
There's an issue with @Serialized when used on a field of type Object and
the actual value is of primitive type (Integer, Long, etc).
@Entity
public class TestClass {
@Serialized
Object data;
}
If e.g. data = new Integer(5) it is saved as an integer property. When the
object is read from the database, Morphia fails since it expects the
property to be a byte[].
This problem happens because DefaultConverters.getEncoder(Object val,
MappedField mf) looks up first in the default typed converters *before*
searching the untyped converters where the SerializedObjectConverter
resides.
Stacktrace:
Caused by: java.lang.RuntimeException:
com.google.code.morphia.mapping.MappingException: The stored data is not a
DBBinary or byte[] instance for TestClass.data ; it is a java.lang.Integer
at
com.google.code.morphia.mapping.ValueMapper.fromDBObject(ValueMapper.java:27)
at com.google.code.morphia.mapping.Mapper.readMappedField(Mapper.java:497)
at com.google.code.morphia.mapping.Mapper.fromDb(Mapper.java:480)
... 14 more
Caused by: com.google.code.morphia.mapping.MappingException: The stored
data is not a DBBinary or byte[] instance for TestClass.data ; it is a
java.lang.Integer
at
com.google.code.morphia.converters.SerializedObjectConverter.decode(SerializedObjectConverter.java:33)
at
com.google.code.morphia.converters.DefaultConverters.fromDBObject(DefaultConverters.java:129)
at
com.google.code.morphia.mapping.ValueMapper.fromDBObject(ValueMapper.java:25)
... 16 more
Comment #1 on issue 377 by scotthernandez: @Serialized doesn't work with
runtime values of primitive types
http://code.google.com/p/morphia/issues/detail?id=377
(No comment was entered for this change.)