DATADOC-207 - Empty custom maps get read correctly.

Eagerly detect the map target type by using the TypeInformation instead of falling back to the raw Map interface.
This commit is contained in:
Oliver Gierke
2011-07-22 10:16:13 +02:00
parent ac9c804aae
commit 101064769c
2 changed files with 21 additions and 2 deletions

View File

@@ -724,7 +724,7 @@ public class MappingMongoConverter extends AbstractMongoConverter implements App
Assert.notNull(dbObject);
Class<?> customMapType = findTypeToBeUsed(dbObject);
Class<?> mapType = customMapType == null ? Map.class : customMapType;
Class<?> mapType = customMapType == null ? type.getType() : customMapType;
Map<Object, Object> map = CollectionFactory.createMap(mapType, dbObject.keySet().size());
Map<String, Object> sourceMap = dbObject.toMap();

View File

@@ -30,7 +30,7 @@ import java.util.List;
import java.util.Locale;
import java.util.Map;
import java.util.Set;
import java.util.SortedMap;
import org.bson.types.ObjectId;
import org.joda.time.LocalDate;
import org.junit.Before;
@@ -396,6 +396,21 @@ public class MappingMongoConverterUnitTests {
assertThat(dbo2.get("_id"), is(ObjectId.class));
}
/**
* @see DATADOC-207
*/
@Test
public void convertsCustomEmptyMapCorrectly() {
DBObject map = new BasicDBObject();
DBObject wrapper = new BasicDBObject("map", map);
ClassWithSortedMap result = converter.read(ClassWithSortedMap.class, wrapper);
assertThat(result, is(ClassWithSortedMap.class));
assertThat(result.map, is(SortedMap.class));
}
class ClassWithEnumProperty {
@@ -424,6 +439,10 @@ public class MappingMongoConverterUnitTests {
Set<Address> addresses;
}
class ClassWithSortedMap {
SortedMap<String, String> map;
}
class ClassWithMapProperty {
Map<Locale, String> map;
}