DATAMONGO-2275 - Fix NPE when mapping MongoJsonSchema used in query.
We fixed a NPE when reading raw Document from a collection using a query matching against a JSON schema. Original pull request: #752.
This commit is contained in:
committed by
Mark Paluch
parent
bede55714c
commit
b900dc6c09
@@ -286,7 +286,7 @@ public class QueryMapper {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (keyword.isJsonSchema()) {
|
if (keyword.isJsonSchema()) {
|
||||||
return schemaMapper.mapSchema(new Document(keyword.getKey(), keyword.getValue()), entity.getType());
|
return schemaMapper.mapSchema(new Document(keyword.getKey(), keyword.getValue()), entity != null ? entity.getType() : Object.class);
|
||||||
}
|
}
|
||||||
|
|
||||||
return new Document(keyword.getKey(), convertSimpleOrDocument(keyword.getValue(), entity));
|
return new Document(keyword.getKey(), convertSimpleOrDocument(keyword.getValue(), entity));
|
||||||
|
|||||||
@@ -21,6 +21,7 @@ import static org.springframework.data.mongodb.core.query.Query.*;
|
|||||||
import static org.springframework.data.mongodb.core.schema.JsonSchemaProperty.*;
|
import static org.springframework.data.mongodb.core.schema.JsonSchemaProperty.*;
|
||||||
|
|
||||||
import lombok.Data;
|
import lombok.Data;
|
||||||
|
import org.bson.Document;
|
||||||
import reactor.test.StepVerifier;
|
import reactor.test.StepVerifier;
|
||||||
|
|
||||||
import org.junit.AfterClass;
|
import org.junit.AfterClass;
|
||||||
@@ -199,6 +200,15 @@ public class JsonSchemaQueryTests {
|
|||||||
.containsExactlyInAnyOrder(jellyBelly, kazmardBoombub);
|
.containsExactlyInAnyOrder(jellyBelly, kazmardBoombub);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test // DATAMONGO-1835
|
||||||
|
public void findsWithSchemaReturningRawDocument() {
|
||||||
|
|
||||||
|
MongoJsonSchema schema = MongoJsonSchema.builder().required("address").build();
|
||||||
|
|
||||||
|
assertThat(template.find(query(matchingDocumentStructure(schema)), Document.class, template.getCollectionName(Person.class)))
|
||||||
|
.hasSize(2);
|
||||||
|
}
|
||||||
|
|
||||||
@Data
|
@Data
|
||||||
static class Person {
|
static class Person {
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user