19
19
import java .util .ArrayList ;
20
20
import java .util .Collections ;
21
21
import java .util .HashMap ;
22
+ import java .util .HashSet ;
22
23
import java .util .List ;
23
24
import java .util .Map ;
25
+ import java .util .Objects ;
26
+ import java .util .Set ;
24
27
import java .util .stream .Collectors ;
25
28
import java .util .stream .IntStream ;
26
29
import java .util .stream .Stream ;
@@ -268,6 +271,16 @@ void shouldHaveHigherDefaultAutoGrowLimit() throws Exception {
268
271
assertThat (((ItemListHolder ) result ).getItems ()).hasSize (260 );
269
272
}
270
273
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
+
271
284
272
285
@ SuppressWarnings ("unchecked" )
273
286
private DataFetchingEnvironment environment (String jsonPayload ) throws JsonProcessingException {
@@ -401,6 +414,36 @@ public int getAge() {
401
414
public void setAge (int age ) {
402
415
this .age = age ;
403
416
}
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
+ }
404
447
}
405
448
406
449
}
0 commit comments