-
Notifications
You must be signed in to change notification settings - Fork 37.7k
/
RequestMappingMessageConversionIntegrationTests.java
671 lines (542 loc) · 22.7 KB
/
RequestMappingMessageConversionIntegrationTests.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
/*
* Copyright 2002-2016 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.springframework.web.reactive.result.method.annotation;
import java.nio.ByteBuffer;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.List;
import java.util.concurrent.CompletableFuture;
import javax.xml.bind.annotation.XmlElement;
import javax.xml.bind.annotation.XmlRootElement;
import io.reactivex.Flowable;
import io.reactivex.Maybe;
import org.junit.Test;
import org.reactivestreams.Publisher;
import reactor.core.publisher.Flux;
import reactor.core.publisher.Mono;
import rx.Completable;
import rx.Observable;
import rx.Single;
import org.springframework.context.ApplicationContext;
import org.springframework.context.annotation.AnnotationConfigApplicationContext;
import org.springframework.context.annotation.ComponentScan;
import org.springframework.context.annotation.Configuration;
import org.springframework.core.ParameterizedTypeReference;
import org.springframework.core.ResolvableType;
import org.springframework.core.io.ClassPathResource;
import org.springframework.core.io.Resource;
import org.springframework.core.io.buffer.DataBuffer;
import org.springframework.core.io.buffer.DataBufferFactory;
import org.springframework.core.io.buffer.DefaultDataBufferFactory;
import org.springframework.http.HttpHeaders;
import org.springframework.http.HttpStatus;
import org.springframework.http.MediaType;
import org.springframework.http.ResponseEntity;
import org.springframework.http.codec.json.Jackson2JsonEncoder;
import org.springframework.http.server.reactive.ZeroCopyIntegrationTests;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.reactive.config.EnableWebReactive;
import static java.util.Arrays.asList;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertTrue;
import static org.springframework.http.MediaType.APPLICATION_XML;
/**
* {@code @RequestMapping} integration tests focusing on serialization and
* deserialization of the request and response body.
*
* @author Rossen Stoyanchev
* @author Sebastien Deleuze
*/
public class RequestMappingMessageConversionIntegrationTests extends AbstractRequestMappingIntegrationTests {
private static final ParameterizedTypeReference<List<Person>> PERSON_LIST =
new ParameterizedTypeReference<List<Person>>() {};
private static final MediaType JSON = MediaType.APPLICATION_JSON;
@Override
protected ApplicationContext initApplicationContext() {
AnnotationConfigApplicationContext wac = new AnnotationConfigApplicationContext();
wac.register(WebConfig.class);
wac.refresh();
return wac;
}
@Test
public void byteBufferResponseBodyWithPublisher() throws Exception {
Person expected = new Person("Robert");
assertEquals(expected, performGet("/raw-response/publisher", JSON, Person.class).getBody());
}
@Test
public void byteBufferResponseBodyWithFlux() throws Exception {
String expected = "Hello!";
assertEquals(expected, performGet("/raw-response/flux", new HttpHeaders(), String.class).getBody());
}
@Test
public void byteBufferResponseBodyWithObservable() throws Exception {
String expected = "Hello!";
assertEquals(expected, performGet("/raw-response/observable", new HttpHeaders(), String.class).getBody());
}
@Test
public void byteBufferResponseBodyWithRxJava2Observable() throws Exception {
String expected = "Hello!";
assertEquals(expected, performGet("/raw-response/rxjava2-observable",
new HttpHeaders(), String.class).getBody());
}
@Test
public void byteBufferResponseBodyWithFlowable() throws Exception {
String expected = "Hello!";
assertEquals(expected, performGet("/raw-response/flowable", new HttpHeaders(), String.class).getBody());
}
@Test
public void personResponseBody() throws Exception {
Person expected = new Person("Robert");
assertEquals(expected, performGet("/person-response/person", JSON, Person.class).getBody());
}
@Test
public void personResponseBodyWithCompletableFuture() throws Exception {
Person expected = new Person("Robert");
assertEquals(expected, performGet("/person-response/completable-future", JSON, Person.class).getBody());
}
@Test
public void personResponseBodyWithMono() throws Exception {
Person expected = new Person("Robert");
assertEquals(expected, performGet("/person-response/mono", JSON, Person.class).getBody());
}
@Test
public void personResponseBodyWithSingle() throws Exception {
Person expected = new Person("Robert");
assertEquals(expected, performGet("/person-response/single", JSON, Person.class).getBody());
}
@Test
public void personResponseBodyWithMonoResponseEntity() throws Exception {
Person expected = new Person("Robert");
assertEquals(expected, performGet("/person-response/mono-response-entity", JSON, Person.class).getBody());
}
@Test
public void personResponseBodyWithList() throws Exception {
List<?> expected = asList(new Person("Robert"), new Person("Marie"));
assertEquals(expected, performGet("/person-response/list", JSON, PERSON_LIST).getBody());
}
@Test
public void personResponseBodyWithPublisher() throws Exception {
List<?> expected = asList(new Person("Robert"), new Person("Marie"));
assertEquals(expected, performGet("/person-response/publisher", JSON, PERSON_LIST).getBody());
}
@Test
public void personResponseBodyWithFlux() throws Exception {
List<?> expected = asList(new Person("Robert"), new Person("Marie"));
assertEquals(expected, performGet("/person-response/flux", JSON, PERSON_LIST).getBody());
}
@Test
public void personResponseBodyWithObservable() throws Exception {
List<?> expected = asList(new Person("Robert"), new Person("Marie"));
assertEquals(expected, performGet("/person-response/observable", JSON, PERSON_LIST).getBody());
}
@Test
public void resource() throws Exception {
ResponseEntity<byte[]> response = performGet("/resource", new HttpHeaders(), byte[].class);
assertEquals(HttpStatus.OK, response.getStatusCode());
assertTrue(response.hasBody());
assertEquals(951, response.getHeaders().getContentLength());
assertEquals(951, response.getBody().length);
assertEquals(new MediaType("image", "x-png"), response.getHeaders().getContentType());
}
@Test
public void personTransform() throws Exception {
assertEquals(new Person("ROBERT"),
performPost("/person-transform/person", JSON, new Person("Robert"),
JSON, Person.class).getBody());
}
@Test
public void personTransformWithCompletableFuture() throws Exception {
assertEquals(new Person("ROBERT"),
performPost("/person-transform/completable-future", JSON, new Person("Robert"),
JSON, Person.class).getBody());
}
@Test
public void personTransformWithMono() throws Exception {
assertEquals(new Person("ROBERT"),
performPost("/person-transform/mono", JSON, new Person("Robert"),
JSON, Person.class).getBody());
}
@Test
public void personTransformWithSingle() throws Exception {
assertEquals(new Person("ROBERT"),
performPost("/person-transform/single", JSON, new Person("Robert"),
JSON, Person.class).getBody());
}
@Test
public void personTransformWithRxJava2Single() throws Exception {
assertEquals(new Person("ROBERT"),
performPost("/person-transform/rxjava2-single", JSON, new Person("Robert"),
JSON, Person.class).getBody());
}
@Test
public void personTransformWithRxJava2Maybe() throws Exception {
assertEquals(new Person("ROBERT"),
performPost("/person-transform/rxjava2-maybe", JSON, new Person("Robert"),
JSON, Person.class).getBody());
}
@Test
public void personTransformWithPublisher() throws Exception {
List<?> req = asList(new Person("Robert"), new Person("Marie"));
List<?> res = asList(new Person("ROBERT"), new Person("MARIE"));
assertEquals(res, performPost("/person-transform/publisher", JSON, req, JSON, PERSON_LIST).getBody());
}
@Test
public void personTransformWithFlux() throws Exception {
List<?> req = asList(new Person("Robert"), new Person("Marie"));
List<?> res = asList(new Person("ROBERT"), new Person("MARIE"));
assertEquals(res, performPost("/person-transform/flux", JSON, req, JSON, PERSON_LIST).getBody());
}
@Test
public void personTransformWithObservable() throws Exception {
List<?> req = asList(new Person("Robert"), new Person("Marie"));
List<?> res = asList(new Person("ROBERT"), new Person("MARIE"));
assertEquals(res, performPost("/person-transform/observable", JSON, req, JSON, PERSON_LIST).getBody());
}
@Test
public void personTransformWithRxJava2Observable() throws Exception {
List<?> req = asList(new Person("Robert"), new Person("Marie"));
List<?> res = asList(new Person("ROBERT"), new Person("MARIE"));
assertEquals(res, performPost("/person-transform/rxjava2-observable", JSON, req, JSON, PERSON_LIST).getBody());
}
@Test
public void personTransformWithFlowable() throws Exception {
List<?> req = asList(new Person("Robert"), new Person("Marie"));
List<?> res = asList(new Person("ROBERT"), new Person("MARIE"));
assertEquals(res, performPost("/person-transform/flowable", JSON, req, JSON, PERSON_LIST).getBody());
}
@Test
public void personCreateWithPublisherJson() throws Exception {
ResponseEntity<Void> entity = performPost("/person-create/publisher", JSON,
asList(new Person("Robert"), new Person("Marie")), null, Void.class);
assertEquals(HttpStatus.OK, entity.getStatusCode());
assertEquals(2, getApplicationContext().getBean(PersonCreateController.class).persons.size());
}
@Test
public void personCreateWithPublisherXml() throws Exception {
People people = new People(new Person("Robert"), new Person("Marie"));
ResponseEntity<Void> response = performPost("/person-create/publisher", APPLICATION_XML, people, null, Void.class);
assertEquals(HttpStatus.OK, response.getStatusCode());
assertEquals(2, getApplicationContext().getBean(PersonCreateController.class).persons.size());
}
@Test
public void personCreateWithMono() throws Exception {
ResponseEntity<Void> entity = performPost(
"/person-create/mono", JSON, new Person("Robert"), null, Void.class);
assertEquals(HttpStatus.OK, entity.getStatusCode());
assertEquals(1, getApplicationContext().getBean(PersonCreateController.class).persons.size());
}
@Test
public void personCreateWithSingle() throws Exception {
ResponseEntity<Void> entity = performPost(
"/person-create/single", JSON, new Person("Robert"), null, Void.class);
assertEquals(HttpStatus.OK, entity.getStatusCode());
assertEquals(1, getApplicationContext().getBean(PersonCreateController.class).persons.size());
}
@Test
public void personCreateWithRxJava2Single() throws Exception {
ResponseEntity<Void> entity = performPost(
"/person-create/rxjava2-single", JSON, new Person("Robert"), null, Void.class);
assertEquals(HttpStatus.OK, entity.getStatusCode());
assertEquals(1, getApplicationContext().getBean(PersonCreateController.class).persons.size());
}
@Test
public void personCreateWithFluxJson() throws Exception {
ResponseEntity<Void> entity = performPost("/person-create/flux", JSON,
asList(new Person("Robert"), new Person("Marie")), null, Void.class);
assertEquals(HttpStatus.OK, entity.getStatusCode());
assertEquals(2, getApplicationContext().getBean(PersonCreateController.class).persons.size());
}
@Test
public void personCreateWithFluxXml() throws Exception {
People people = new People(new Person("Robert"), new Person("Marie"));
ResponseEntity<Void> response = performPost("/person-create/flux", APPLICATION_XML, people, null, Void.class);
assertEquals(HttpStatus.OK, response.getStatusCode());
assertEquals(2, getApplicationContext().getBean(PersonCreateController.class).persons.size());
}
@Test
public void personCreateWithObservableJson() throws Exception {
ResponseEntity<Void> entity = performPost("/person-create/observable", JSON,
asList(new Person("Robert"), new Person("Marie")), null, Void.class);
assertEquals(HttpStatus.OK, entity.getStatusCode());
assertEquals(2, getApplicationContext().getBean(PersonCreateController.class).persons.size());
}
@Test
public void personCreateWithRxJava2ObservableJson() throws Exception {
ResponseEntity<Void> entity = performPost("/person-create/rxjava2-observable", JSON,
asList(new Person("Robert"), new Person("Marie")), null, Void.class);
assertEquals(HttpStatus.OK, entity.getStatusCode());
assertEquals(2, getApplicationContext().getBean(PersonCreateController.class).persons.size());
}
@Test
public void personCreateWithObservableXml() throws Exception {
People people = new People(new Person("Robert"), new Person("Marie"));
ResponseEntity<Void> response = performPost("/person-create/observable", APPLICATION_XML, people, null, Void.class);
assertEquals(HttpStatus.OK, response.getStatusCode());
assertEquals(2, getApplicationContext().getBean(PersonCreateController.class).persons.size());
}
@Test
public void personCreateWithRxJava2ObservableXml() throws Exception {
People people = new People(new Person("Robert"), new Person("Marie"));
ResponseEntity<Void> response = performPost("/person-create/rxjava2-observable", APPLICATION_XML, people, null, Void.class);
assertEquals(HttpStatus.OK, response.getStatusCode());
assertEquals(2, getApplicationContext().getBean(PersonCreateController.class).persons.size());
}
@Test
public void personCreateWithFlowableJson() throws Exception {
ResponseEntity<Void> entity = performPost("/person-create/flowable", JSON,
asList(new Person("Robert"), new Person("Marie")), null, Void.class);
assertEquals(HttpStatus.OK, entity.getStatusCode());
assertEquals(2, getApplicationContext().getBean(PersonCreateController.class).persons.size());
}
@Test
public void personCreateWithFlowableXml() throws Exception {
People people = new People(new Person("Robert"), new Person("Marie"));
ResponseEntity<Void> response = performPost("/person-create/flowable", APPLICATION_XML, people, null, Void.class);
assertEquals(HttpStatus.OK, response.getStatusCode());
assertEquals(2, getApplicationContext().getBean(PersonCreateController.class).persons.size());
}
@Configuration
@EnableWebReactive
@ComponentScan(resourcePattern = "**/RequestMappingMessageConversionIntegrationTests$*.class")
@SuppressWarnings({"unused", "WeakerAccess"})
static class WebConfig {
}
@RestController
@RequestMapping("/raw-response")
@SuppressWarnings("unused")
private static class RawResponseBodyController {
@GetMapping("/publisher")
public Publisher<ByteBuffer> getPublisher() {
DataBufferFactory dataBufferFactory = new DefaultDataBufferFactory();
Jackson2JsonEncoder encoder = new Jackson2JsonEncoder();
return encoder.encode(Mono.just(new Person("Robert")), dataBufferFactory,
ResolvableType.forClass(Person.class), JSON, Collections.emptyMap()).map(DataBuffer::asByteBuffer);
}
@GetMapping("/flux")
public Flux<ByteBuffer> getFlux() {
return Flux.just(ByteBuffer.wrap("Hello!".getBytes()));
}
@GetMapping("/observable")
public Observable<ByteBuffer> getObservable() {
return Observable.just(ByteBuffer.wrap("Hello!".getBytes()));
}
@GetMapping("/rxjava2-observable")
public io.reactivex.Observable<ByteBuffer> getRxJava2Observable() {
return io.reactivex.Observable.just(ByteBuffer.wrap("Hello!".getBytes()));
}
@GetMapping("/flowable")
public Flowable<ByteBuffer> getFlowable() {
return Flowable.just(ByteBuffer.wrap("Hello!".getBytes()));
}
}
@RestController
@RequestMapping("/person-response")
@SuppressWarnings("unused")
private static class PersonResponseBodyController {
@GetMapping("/person")
public Person getPerson() {
return new Person("Robert");
}
@GetMapping("/completable-future")
public CompletableFuture<Person> getCompletableFuture() {
return CompletableFuture.completedFuture(new Person("Robert"));
}
@GetMapping("/mono")
public Mono<Person> getMono() {
return Mono.just(new Person("Robert"));
}
@GetMapping("/single")
public Single<Person> getSingle() {
return Single.just(new Person("Robert"));
}
@GetMapping("/mono-response-entity")
public ResponseEntity<Mono<Person>> getMonoResponseEntity() {
Mono<Person> body = Mono.just(new Person("Robert"));
return ResponseEntity.ok(body);
}
@GetMapping("/list")
public List<Person> getList() {
return asList(new Person("Robert"), new Person("Marie"));
}
@GetMapping("/publisher")
public Publisher<Person> getPublisher() {
return Flux.just(new Person("Robert"), new Person("Marie"));
}
@GetMapping("/flux")
public Flux<Person> getFlux() {
return Flux.just(new Person("Robert"), new Person("Marie"));
}
@GetMapping("/observable")
public Observable<Person> getObservable() {
return Observable.just(new Person("Robert"), new Person("Marie"));
}
}
@RestController
@SuppressWarnings("unused")
private static class ResourceController {
@GetMapping("/resource")
public Resource resource() {
return new ClassPathResource("spring.png", ZeroCopyIntegrationTests.class);
}
}
@RestController
@RequestMapping("/person-transform")
@SuppressWarnings("unused")
private static class PersonTransformationController {
@PostMapping("/person")
public Person transformPerson(@RequestBody Person person) {
return new Person(person.getName().toUpperCase());
}
@PostMapping("/completable-future")
public CompletableFuture<Person> transformCompletableFuture(
@RequestBody CompletableFuture<Person> personFuture) {
return personFuture.thenApply(person -> new Person(person.getName().toUpperCase()));
}
@PostMapping("/mono")
public Mono<Person> transformMono(@RequestBody Mono<Person> personFuture) {
return personFuture.map(person -> new Person(person.getName().toUpperCase()));
}
@PostMapping("/single")
public Single<Person> transformSingle(@RequestBody Single<Person> personFuture) {
return personFuture.map(person -> new Person(person.getName().toUpperCase()));
}
@PostMapping("/rxjava2-single")
public io.reactivex.Single<Person> transformRxJava2Single(@RequestBody io.reactivex.Single<Person> personFuture) {
return personFuture.map(person -> new Person(person.getName().toUpperCase()));
}
@PostMapping("/rxjava2-maybe")
public Maybe<Person> transformRxJava2Maybe(@RequestBody Maybe<Person> personFuture) {
return personFuture.map(person -> new Person(person.getName().toUpperCase()));
}
@PostMapping("/publisher")
public Publisher<Person> transformPublisher(@RequestBody Publisher<Person> persons) {
return Flux
.from(persons)
.map(person -> new Person(person.getName().toUpperCase()));
}
@PostMapping("/flux")
public Flux<Person> transformFlux(@RequestBody Flux<Person> persons) {
return persons.map(person -> new Person(person.getName().toUpperCase()));
}
@PostMapping("/observable")
public Observable<Person> transformObservable(@RequestBody Observable<Person> persons) {
return persons.map(person -> new Person(person.getName().toUpperCase()));
}
@PostMapping("/rxjava2-observable")
public io.reactivex.Observable<Person> transformObservable(@RequestBody io.reactivex.Observable<Person> persons) {
return persons.map(person -> new Person(person.getName().toUpperCase()));
}
@PostMapping("/flowable")
public Flowable<Person> transformFlowable(@RequestBody Flowable<Person> persons) {
return persons.map(person -> new Person(person.getName().toUpperCase()));
}
}
@RestController
@RequestMapping("/person-create")
@SuppressWarnings("unused")
private static class PersonCreateController {
final List<Person> persons = new ArrayList<>();
@PostMapping("/publisher")
public Publisher<Void> createWithPublisher(@RequestBody Publisher<Person> publisher) {
return Flux.from(publisher).doOnNext(persons::add).then();
}
@PostMapping("/mono")
public Mono<Void> createWithMono(@RequestBody Mono<Person> mono) {
return mono.doOnNext(persons::add).then();
}
@PostMapping("/single")
public Completable createWithSingle(@RequestBody Single<Person> single) {
return single.map(persons::add).toCompletable();
}
@PostMapping("/rxjava2-single")
public io.reactivex.Completable createWithRxJava2Single(@RequestBody io.reactivex.Single<Person> single) {
return single.map(persons::add).toCompletable();
}
@PostMapping("/flux")
public Mono<Void> createWithFlux(@RequestBody Flux<Person> flux) {
return flux.doOnNext(persons::add).then();
}
@PostMapping("/observable")
public Observable<Void> createWithObservable(@RequestBody Observable<Person> observable) {
return observable.toList().doOnNext(persons::addAll).flatMap(document -> Observable.empty());
}
@PostMapping("/rxjava2-observable")
public io.reactivex.Completable createWithRxJava2Observable(@RequestBody io.reactivex.Observable<Person> observable) {
return observable.toList().doOnSuccess(persons::addAll).toCompletable();
}
@PostMapping("/flowable")
public io.reactivex.Completable createWithFlowable(@RequestBody Flowable<Person> flowable) {
return flowable.toList().doOnSuccess(persons::addAll).toCompletable();
}
}
@XmlRootElement
@SuppressWarnings("WeakerAccess")
private static class Person {
private String name;
@SuppressWarnings("unused")
public Person() {
}
public Person(String name) {
this.name = name;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
@Override
public boolean equals(Object o) {
if (this == o) {
return true;
}
if (o == null || getClass() != o.getClass()) {
return false;
}
Person person = (Person) o;
return !(this.name != null ? !this.name.equals(person.name) : person.name != null);
}
@Override
public int hashCode() {
return this.name != null ? this.name.hashCode() : 0;
}
@Override
public String toString() {
return "Person{" +
"name='" + name + '\'' +
'}';
}
}
@XmlRootElement
@SuppressWarnings({"WeakerAccess", "unused"})
private static class People {
private List<Person> persons = new ArrayList<>();
public People() {
}
public People(Person... persons) {
this.persons.addAll(Arrays.asList(persons));
}
@XmlElement
public List<Person> getPerson() {
return this.persons;
}
}
}