'I am using webclient in springcloud to make a call, I want to format the returned data, convert Map to XML

  • This is my code, I want to convert the returned Mono to XML format after calling it using webclient
@RequestMapping("/test")
    public Mono test(ServerHttpRequest request) {
        return DataBufferUtils.join(request.getBody()).flatMap(dataBuffer -> {
            byte[] oldBytes = new byte[dataBuffer.readableByteCount()];
            dataBuffer.read(oldBytes);
            String bodyString = new String(oldBytes, StandardCharsets.UTF_8);
            Map<String, Object> map = XmlUtil.xmlToMap(bodyString);
            WebClient build = builder.build();
            Mono<Map> mapMono = build.post().uri(url).contentType(MediaType.APPLICATION_JSON)
                    .bodyValue(map).retrieve().bodyToMono(Map.class);
            return Mono.just(ResponseEntity.ok().contentType(MediaType.APPLICATION_XML).body(mapMono));
        });
       
    }
xml


Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source