Skip to content

Commit

Permalink
Fix NullPointerException when entity not found
Browse files Browse the repository at this point in the history
  • Loading branch information
VanRoy committed Jan 31, 2017
1 parent 205864e commit 5f3f0fc
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ public EntityMapper getEntityMapper() {
}

public <T> T mapResult(DocumentResult response, Class<T> clazz) {
T result = mapEntity(response.getJsonObject().get("_source").toString(), clazz);
T result = mapEntity(response.getSourceAsString(), clazz);
if (result != null) {
setPersistentEntityId(result, response.getId(), clazz);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -159,6 +159,17 @@ public void shouldReturnObjectForGivenId() {
assertEquals(sampleEntity, sampleEntity1);
}

@Test
public void shouldReturnNullForInexistentId() {
// given
// when
GetQuery getQuery = new GetQuery();
getQuery.setId("1");
SampleEntity sampleEntity1 = elasticsearchTemplate.queryForObject(getQuery, SampleEntity.class);
// then
assertNull("entity must be null....", sampleEntity1);
}

@Test
public void shouldReturnObjectsForGivenIdsUsingMultiGet() {
// given
Expand Down

0 comments on commit 5f3f0fc

Please sign in to comment.