DATAMONGO-376 - Fixed potential NPE in SpringDataMongodbSerializer.
This commit is contained in:
@@ -252,7 +252,7 @@ public class QueryDslMongoRepository<T, ID extends Serializable> extends SimpleM
|
||||
Path<?> parent = metadata.getParent();
|
||||
MongoPersistentEntity<?> entity = mappingContext.getPersistentEntity(parent.getType());
|
||||
MongoPersistentProperty property = entity.getPersistentProperty(metadata.getExpression().toString());
|
||||
return property.getFieldName();
|
||||
return property == null ? super.getKeyForPath(expr, metadata) : property.getFieldName();
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -28,6 +28,7 @@ import org.springframework.data.mongodb.core.convert.MappingMongoConverter;
|
||||
import org.springframework.data.mongodb.core.convert.MongoConverter;
|
||||
import org.springframework.data.mongodb.core.mapping.Field;
|
||||
import org.springframework.data.mongodb.core.mapping.MongoMappingContext;
|
||||
import org.springframework.data.mongodb.repository.QAddress;
|
||||
import org.springframework.data.mongodb.repository.QPerson;
|
||||
import org.springframework.data.mongodb.repository.support.QueryDslMongoRepository.SpringDataMongodbSerializer;
|
||||
|
||||
@@ -87,6 +88,16 @@ public class SpringDataMongodbSerializerUnitTests {
|
||||
assertThat(value, is(reference));
|
||||
}
|
||||
|
||||
/**
|
||||
* @see DATAMONGO-376
|
||||
*/
|
||||
@Test
|
||||
public void returnsEmptyStringIfNoPathExpressionIsGiven() {
|
||||
|
||||
QAddress address = QPerson.person.shippingAddresses.any();
|
||||
assertThat(serializer.getKeyForPath(address, address.getMetadata()), is(""));
|
||||
}
|
||||
|
||||
class Address {
|
||||
String street;
|
||||
@Field("zip_code")
|
||||
|
||||
Reference in New Issue
Block a user