DATAMONGO-1118 - Simplified potentiallyConvertMapKey in MappingMongoConverter.
Fixed typos in CustomConversions. Original pull request: #260.
This commit is contained in:
committed by
Oliver Gierke
parent
d8bb644b30
commit
79fdf44d24
@@ -240,9 +240,9 @@ public class CustomConversions {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns the target type we can write an onject of the given source type to. The returned type might be a subclass
|
* Returns the target type we can write an inject of the given source type to. The returned type might be a subclass
|
||||||
* oth the given expected type though. If {@code expectedTargetType} is {@literal null} we will simply return the
|
* of the given expected type though. If {@code expectedTargetType} is {@literal null} we will simply return the first
|
||||||
* first target type matching or {@literal null} if no conversion can be found.
|
* target type matching or {@literal null} if no conversion can be found.
|
||||||
*
|
*
|
||||||
* @param sourceType must not be {@literal null}
|
* @param sourceType must not be {@literal null}
|
||||||
* @param requestedTargetType
|
* @param requestedTargetType
|
||||||
|
|||||||
@@ -627,7 +627,7 @@ public class MappingMongoConverter extends AbstractMongoConverter implements App
|
|||||||
Object val = entry.getValue();
|
Object val = entry.getValue();
|
||||||
if (conversions.isSimpleType(key.getClass())) {
|
if (conversions.isSimpleType(key.getClass())) {
|
||||||
|
|
||||||
String simpleKey = potentiallyConvertMapKey(key);
|
String simpleKey = potentiallyEscapeMapKey(potentiallyConvertMapKey(key));
|
||||||
if (val == null || conversions.isSimpleType(val.getClass())) {
|
if (val == null || conversions.isSimpleType(val.getClass())) {
|
||||||
writeSimpleInternal(val, dbo, simpleKey);
|
writeSimpleInternal(val, dbo, simpleKey);
|
||||||
} else if (val instanceof Collection || val.getClass().isArray()) {
|
} else if (val instanceof Collection || val.getClass().isArray()) {
|
||||||
@@ -650,16 +650,15 @@ public class MappingMongoConverter extends AbstractMongoConverter implements App
|
|||||||
|
|
||||||
private String potentiallyConvertMapKey(Object key) {
|
private String potentiallyConvertMapKey(Object key) {
|
||||||
|
|
||||||
String stringKey = null;
|
if (key instanceof String) {
|
||||||
if (key instanceof String
|
return (String) key;
|
||||||
|| !(conversions.hasCustomWriteTarget(key.getClass()) && conversions.getCustomWriteTarget(key.getClass())
|
|
||||||
.equals(String.class))) {
|
|
||||||
stringKey = key.toString();
|
|
||||||
} else {
|
|
||||||
stringKey = (String) getPotentiallyConvertedSimpleWrite(key);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return potentiallyEscapeMapKey(stringKey);
|
if (conversions.hasCustomWriteTarget(key.getClass(), String.class)) {
|
||||||
|
return (String) getPotentiallyConvertedSimpleWrite(key);
|
||||||
|
}
|
||||||
|
|
||||||
|
return key.toString();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
Reference in New Issue
Block a user