1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17 package org.bremersee.apiclient.webflux.contract.spring;
18
19 import static java.util.Objects.nonNull;
20
21 import org.bremersee.apiclient.webflux.InvocationParameter;
22 import org.springframework.web.reactive.function.BodyInserters;
23 import org.springframework.web.reactive.function.client.WebClient.RequestBodyUriSpec;
24 import org.springframework.web.reactive.function.client.WebClient.RequestHeadersUriSpec;
25
26
27
28
29
30
31 public class ValueInserter extends SingleBodyInserter<Object> {
32
33 @Override
34 protected boolean isPossibleBodyValue(InvocationParameter invocationParameter) {
35 return nonNull(invocationParameter.getValue());
36 }
37
38 @Override
39 protected Object mapBody(InvocationParameter invocationParameter) {
40 return invocationParameter.getValue();
41 }
42
43 @Override
44 protected RequestHeadersUriSpec<?> insert(Object body, RequestBodyUriSpec requestBodyUriSpec) {
45
46 return (RequestHeadersUriSpec) requestBodyUriSpec.body(BodyInserters.fromValue(body));
47 }
48
49 }