Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -213,7 +213,7 @@ private <T> Collection<T> createCollection(
int i = 0;
for (Object rawValue : rawCollection) {
segments.push("[" + i++ + "]");
if (elementClass.isAssignableFrom(rawValue.getClass())) {
if (rawValue == null || elementClass.isAssignableFrom(rawValue.getClass())) {
collection.add((T) rawValue);
}
else if (rawValue instanceof Map) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
import com.fasterxml.jackson.databind.ObjectMapper;
import graphql.schema.DataFetchingEnvironment;
import graphql.schema.DataFetchingEnvironmentImpl;
import org.assertj.core.api.CollectionAssert;
import org.junit.jupiter.api.Test;

import org.springframework.core.ResolvableType;
Expand Down Expand Up @@ -281,6 +282,44 @@ void shouldUseTargetCollectionType() throws Exception {
assertThat(((ItemSetHolder) result).getItems()).hasSize(5);
}

@Test
@SuppressWarnings("unchecked")
void list() throws Exception {
Object result = this.binder.bind(
environment("{\"key\": [\"1\", \"2\", \"3\"]}"),
"key",
ResolvableType.forClassWithGenerics(List.class, String.class)
);

assertThat(result).isNotNull().isInstanceOf(List.class);
new CollectionAssert<>((List<String>) result).containsExactly("1", "2", "3");
}

@Test
@SuppressWarnings("unchecked")
void listWithNullItem() throws Exception {
Object result = this.binder.bind(
environment("{\"key\": [\"1\", null, \"3\"]}"),
"key",
ResolvableType.forClassWithGenerics(List.class, String.class)
);

assertThat(result).isNotNull().isInstanceOf(List.class);
new CollectionAssert<>((List<String>) result).containsExactly("1", null, "3");
}

@Test
@SuppressWarnings("unchecked")
void emptyList() throws Exception {
Object result = this.binder.bind(
environment("{\"key\": []}"),
"key",
ResolvableType.forClassWithGenerics(List.class, String.class)
);

assertThat(result).isNotNull().isInstanceOf(List.class);
new CollectionAssert<>((List<String>) result).isEmpty();
}

@SuppressWarnings("unchecked")
private DataFetchingEnvironment environment(String jsonPayload) throws JsonProcessingException {
Expand Down