Closed
Description
Andrew Onischenko opened DATAMONGO-1423 and commented
When trying to perform a direct update a nested document which is a map by
$set : {'metadata.thumbnails' : Map<Enum, String>}
the the map keys are not converted
Meanwhile, updating the core level object works properly
$set : {a: metadata}
For example:
Entity class
public class Video {
....
private VideoMetadata metadata;
....
}
Nested object
public class VideoMetadata {
....
private Map<ThumbnailType, String> thumbnails;
....
}
Enum
public enum ThumbnailType {
DEFAULT, MEDIUM, HIGH, STANDARD, MAXRES
}
Invoked Dao method to update thumbnails
Query query = Query.query(Criteria.where("_id").is(id);
Update update = new Update()
.set("metadata.thumbnails", metadata.getThumbnails());
.set("metadata2", metadata);
}
mongoOps.updateFirst(query, update, Video.class);
Just after performing the update my objects looks like
{
"_id" : ... ,
"_class" : ... ,
......
"metadata" : {
"thumbnails" : {
"MEDIUM" : "a",
"DEFAULT" : "b",
"STANDARD" : "c"
},
"metadata2" : {
"thumbnails" : {
"medium" : "a",
"default" : "b",
"standard" : "c"
}
}
}
The only workaround I can find is to call converter manually :
DBObject dbObject = new BasicDBObject();
mongoOps.getConverter().write(metadata.getThumbnails(), dbObject);
dbObject.removeField("_class");
update.set("metadata.thumbnails", dbObject);
Affects: 1.8.4 (Gosling SR4), 1.9.1 (Hopper SR1)
Attachments:
- screenshot-1.png (21.69 kB)
Issue Links:
- DATAMONGO-1486 Changes to MappingMongoConverter Result in Class Cast Exception
Referenced from: pull request #365
Backported to: 1.9.2 (Hopper SR2), 1.8.5 (Gosling SR5)