2022. 1. 18. 22:05
@NoArgsConstructor
public class APIUtil<T> {
private static ObjectMapper objectMapper;
private static Map parameters;
private WebClient webClient;
@Autowired
public APIUtil(WebClient webClient){
this.webClient = webClient;
}
public Mono<T> post(Object obj, String URL, Class toValueType){
objectMapper = new ObjectMapper();
parameters = new HashMap<String, String>();
parameters = objectMapper.convertValue(obj, Map.class);
Mono<T> t = webClient.post()
.uri(uriBuilder -> uriBuilder.path(URL)
.build())
.contentType(MediaType.APPLICATION_JSON)
.accept(MediaType.APPLICATION_JSON)
.bodyValue(parameters) //body (MultiValueMap 사용시 500 Error)
.retrieve()
.bodyToMono(toValueType);
return t;
}
}
'Spring Framework > Spring' 카테고리의 다른 글
[Spring] WebClient @Bean SSL 설정 (0) | 2022.01.18 |
---|---|
[Spring Security] 사용자 로그인 상태 체크 (0) | 2022.01.18 |
[Spring] JSON 구조 데이터 받기 (0) | 2021.11.29 |
[JAVA] Date 클래스(java.sql) -> Date.valueOf(String) (0) | 2021.09.30 |
[Web] Cookie (쿠키 생성, 읽기) 방법 (0) | 2021.07.20 |