1919import java .util .ArrayList ;
2020import java .util .Collections ;
2121import java .util .HashMap ;
22+ import java .util .HashSet ;
2223import java .util .List ;
2324import java .util .Map ;
25+ import java .util .Objects ;
26+ import java .util .Set ;
2427import java .util .stream .Collectors ;
2528import java .util .stream .IntStream ;
2629import java .util .stream .Stream ;
@@ -268,6 +271,16 @@ void shouldHaveHigherDefaultAutoGrowLimit() throws Exception {
268271assertThat (((ItemListHolder ) result ).getItems ()).hasSize (260 );
269272}
270273
274+ @ Test
275+ void shouldUseTargetCollectionType () throws Exception {
276+ String items = IntStream .range (0 , 5 ).mapToObj (value -> "{\" name\" :\" test" + value + "\" }" ).collect (Collectors .joining ("," ));
277+ Object result = this .binder .bind (
278+ environment ("{\" key\" :{\" items\" :[" + items + "]}}" ), "key" ,
279+ ResolvableType .forClass (ItemSetHolder .class ));
280+ assertThat (result ).isNotNull ().isInstanceOf (ItemSetHolder .class );
281+ assertThat (((ItemSetHolder ) result ).getItems ()).hasSize (5 );
282+ }
283+
271284
272285@ SuppressWarnings ("unchecked" )
273286private DataFetchingEnvironment environment (String jsonPayload ) throws JsonProcessingException {
@@ -401,6 +414,36 @@ public int getAge() {
401414public void setAge (int age ) {
402415this .age = age ;
403416}
417+
418+ @ Override
419+ public boolean equals (Object o ) {
420+ if (this == o ) return true ;
421+ if (o == null || getClass () != o .getClass ()) return false ;
422+ Item item = (Item ) o ;
423+ return name .equals (item .name );
424+ }
425+
426+ @ Override
427+ public int hashCode () {
428+ return Objects .hash (name );
429+ }
430+ }
431+
432+ static class ItemSetHolder {
433+
434+ private Set <Item > items ;
435+
436+ public ItemSetHolder (Set <Item > items ) {
437+ this .items = items ;
438+ }
439+
440+ public Set <Item > getItems () {
441+ return items ;
442+ }
443+
444+ public void setItems (Set <Item > items ) {
445+ this .items = items ;
446+ }
404447}
405448
406449}
0 commit comments