Skip to content
This repository was archived by the owner on Dec 19, 2023. It is now read-only.

Commit 7482def

Browse files
authored
Merge pull request #320 from BlasiusSecundus/feature/test-response-improvements
feat: added method to type-safely get List of objects
2 parents 3d9f9c7 + d646420 commit 7482def

File tree

1 file changed

+6
-0
lines changed

1 file changed

+6
-0
lines changed

graphql-spring-boot-test/src/main/java/com/graphql/spring/boot/test/GraphQLResponse.java

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
import org.springframework.http.ResponseEntity;
99

1010
import java.io.IOException;
11+
import java.util.List;
1112
import java.util.Objects;
1213

1314
public class GraphQLResponse {
@@ -37,6 +38,11 @@ public <T> T get(String path, Class<T> type) {
3738
return context.read(path, type);
3839
}
3940

41+
public <T> List<T> getList(String path, Class<T> type) {
42+
final List<?> raw = context.read(path, List.class);
43+
return mapper.convertValue(raw, mapper.getTypeFactory().constructCollectionType(List.class, type));
44+
}
45+
4046
public ReadContext context() {
4147
return context;
4248
}

0 commit comments

Comments
 (0)