Skip to content

Commit

Permalink
GH-671 - Fix mapping exception when querying for a narrower type then…
Browse files Browse the repository at this point in the history
… returned from the database.

- Fix check if result type is assignable to provided generic type
- Add test to verify result type compatibility check

This fixes #671.
  • Loading branch information
nioertel authored and michael-simons committed Oct 28, 2019
1 parent 59f8422 commit d136089
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ public <T> T queryForObject(Class<T> type, String cypher, Map<String, ?> paramet

T next = results.iterator().next();

if (!next.getClass().isAssignableFrom(type)) {
if (!type.isAssignableFrom(next.getClass())) {

String typeOfResult = next.getClass().getName();
String wantedType = type.getName();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -696,6 +696,12 @@ public void shouldThrowExceptionIfTypeMismatchesInQueryForObject() {
Restaurant.class.getName());
}

@Test // GH-671
public void shouldNotThrowExceptionIfTypeIsSuperTypeOfResultObject() {
session.queryForObject(Long.class, "MATCH (n:User) return count(n)", emptyMap());
session.queryForObject(Number.class, "MATCH (n:User) return count(n)", emptyMap());
}

@Test
public void queryForObjectFindsNestedClasses() {

Expand Down

0 comments on commit d136089

Please sign in to comment.