DATAMONGO-1998 - Polishing.

Switch id field name check to equals or to match the last property path segment.

Original pull request: #567.
This commit is contained in:
Mark Paluch
2018-06-06 11:34:20 +02:00
parent 3785a52676
commit f82b791f72
2 changed files with 7 additions and 7 deletions

View File

@@ -20,7 +20,6 @@ import java.util.HashSet;
import java.util.Set;
import java.util.regex.Pattern;
import com.mongodb.util.JSON;
import org.springframework.data.mapping.context.MappingContext;
import org.springframework.data.mongodb.core.convert.MongoConverter;
import org.springframework.data.mongodb.core.convert.QueryMapper;
@@ -31,6 +30,7 @@ import org.springframework.util.ClassUtils;
import com.mongodb.DBObject;
import com.mongodb.DBRef;
import com.mongodb.util.JSON;
import com.querydsl.core.types.Constant;
import com.querydsl.core.types.Expression;
import com.querydsl.core.types.Operation;
@@ -116,7 +116,7 @@ class SpringDataMongodbSerializer extends MongodbSerializer {
@Override
protected DBObject asDBObject(String key, Object value) {
if (key.endsWith(ID_KEY)) {
if (ID_KEY.equals(key) || (key != null && key.endsWith("." + ID_KEY))) {
return convertId(key, value);
}
return super.asDBObject(key, value instanceof Pattern ? value : converter.convertToMongoType(value));
@@ -134,8 +134,7 @@ class SpringDataMongodbSerializer extends MongodbSerializer {
Object convertedId = mapper.convertId(idValue);
DBObject mappedIdValue = mapper.getMappedObject(super.asDBObject(key, convertedId),
null);
DBObject mappedIdValue = mapper.getMappedObject(super.asDBObject(key, convertedId), null);
return (DBObject) JSON.parse(JSON.serialize(mappedIdValue));
}

View File

@@ -20,6 +20,7 @@ import static org.junit.Assert.*;
import static org.springframework.data.mongodb.core.DBObjectTestUtils.*;
import java.util.Collections;
import java.util.List;
import org.bson.types.ObjectId;
import org.hamcrest.Matchers;
@@ -50,7 +51,7 @@ import com.querydsl.core.types.dsl.StringPath;
/**
* Unit tests for {@link SpringDataMongodbSerializer}.
*
*
* @author Oliver Gierke
* @author Christoph Strobl
*/
@@ -158,9 +159,9 @@ public class SpringDataMongodbSerializerUnitTests {
DBObject serialized = serializer.asDBObject("_id", new BasicDBObject("$in", objectIds));
DBObject _id = getAsDBObject(serialized, "_id");
Object[] $in = getTypedValue(_id, "$in", Object[].class);
List<ObjectId> $in = getTypedValue(_id, "$in", List.class);
assertThat($in, Matchers.<Object> arrayContaining(firstId, secondId));
assertThat($in, contains(firstId, secondId));
}
@Test // DATAMONGO-1485