google-code-export / morphia

Automatically exported from code.google.com/p/morphia
1 stars 0 forks source link

UUID for Map keys does not work #320

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
Morphia 0.99
Driver 2.6.3
Mongo 1.8.2

UUID map keys are converted to string when writing, but not back to uuids when 
reading. A simple converter seems to fix this.

public class UUIDConverter extends TypeConverter
implements SimpleValueConverter {

    public UUIDConverter() { super(UUID.class); }

    public Object encode(Object value, MappedField optionalExtraInfo) {
        UUID uuid = (UUID) value;
        if (uuid == null) { return null; }
        return uuid.toString();
    }

    public Object decode(Class targetClass, Object fromDBObject, 
            MappedField optionalExtraInfo) throws MappingException {
        String object = (String) fromDBObject;
        return object == null ? null : UUID.fromString(object); 
    }
}

Original issue reported on code.google.com by stu...@googlemail.com on 5 Sep 2011 at 9:26

GoogleCodeExporter commented 9 years ago
This issue was closed by revision r1788.

Original comment by scotthernandez on 19 Nov 2011 at 2:59

GoogleCodeExporter commented 9 years ago

Original comment by scotthernandez on 19 Nov 2011 at 2:59