DATAMONGO-376 - Fixed potential NPE in SpringDataMongodbSerializer.

This commit is contained in:
Oliver Gierke
2012-01-12 12:23:51 +01:00
parent b190f22551
commit 19879b8dab
2 changed files with 12 additions and 1 deletions

View File

@@ -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

View File

@@ -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")