DATAMONGO-1486 - Fix ClassCastException when mapping non-String Map key for updates.
We now make sure to convert Map keys into Strings when mapping update values for Map properties. Original pull request: #387.
This commit is contained in:
committed by
Oliver Gierke
parent
a8751249fd
commit
2ca3df1ff4
@@ -1012,7 +1012,8 @@ public class MappingMongoConverter extends AbstractMongoConverter implements App
|
|||||||
TypeInformation<? extends Object> valueTypeHint = typeHint != null && typeHint.getMapValueType() != null
|
TypeInformation<? extends Object> valueTypeHint = typeHint != null && typeHint.getMapValueType() != null
|
||||||
? typeHint.getMapValueType() : typeHint;
|
? typeHint.getMapValueType() : typeHint;
|
||||||
|
|
||||||
converted.put(convertToMongoType(entry.getKey()), convertToMongoType(entry.getValue(), valueTypeHint));
|
converted.put(getPotentiallyConvertedSimpleWrite(entry.getKey()).toString(),
|
||||||
|
convertToMongoType(entry.getValue(), valueTypeHint));
|
||||||
}
|
}
|
||||||
|
|
||||||
return new BasicDBObject(converted);
|
return new BasicDBObject(converted);
|
||||||
|
|||||||
@@ -914,6 +914,24 @@ public class UpdateMapperUnitTests {
|
|||||||
assertThat(result, isBsonObject().containing("$set.enumAsMapKey.V", 100));
|
assertThat(result, isBsonObject().containing("$set.enumAsMapKey.V", 100));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @see DATAMONGO-1486
|
||||||
|
*/
|
||||||
|
@Test
|
||||||
|
public void mappingShouldConvertMapKeysToString() {
|
||||||
|
|
||||||
|
Update update = new Update().set("map", Collections.singletonMap(25, "#StarTrek50"));
|
||||||
|
DBObject mappedUpdate = mapper.getMappedObject(update.getUpdateObject(),
|
||||||
|
context.getPersistentEntity(EntityWithObjectMap.class));
|
||||||
|
|
||||||
|
DBObject $set = getAsDBObject(mappedUpdate, "$set");
|
||||||
|
DBObject mapToSet = getAsDBObject($set, "map");
|
||||||
|
|
||||||
|
for (Object key : mapToSet.keySet()) {
|
||||||
|
assertThat(key, instanceOf(String.class));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
static class DomainTypeWrappingConcreteyTypeHavingListOfInterfaceTypeAttributes {
|
static class DomainTypeWrappingConcreteyTypeHavingListOfInterfaceTypeAttributes {
|
||||||
ListModelWrapper concreteTypeWithListAttributeOfInterfaceType;
|
ListModelWrapper concreteTypeWithListAttributeOfInterfaceType;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user