Following code works fine while returning JSON
public Mono<ServerResponse> postUpload(ServerRequest request) {
final Flux<Object> stringFlux = request.body(BodyExtractors.toParts())
.flatMap(filePart -> filePart.content().map(dataBuffer -> {
byte[] bytes = new byte[dataBuffer.readableByteCount()];
dataBuffer.read(bytes);
DataBufferUtils.release(dataBuffer);
byte[] resMessage = new byte[1024];
resMessage = helper.postUpload(bytes, headers);
String resposeMessage = new String(resMessage, StandardCharsets.UTF_8);
return resposeMessage;
}).doOnError(e -> LOGGER.error("Error on Processing file", e)));
return ServerResponse.ok().contentType(MediaType.APPLICATION_JSON).body(stringFlux, Object.class);
}
But I get error if I return XML (replaced JSON in the last line with XML)
return ServerResponse.ok().contentType(MediaType.APPLICATION_XML).body(stringFlux, Object.class);
Error message I get is Content type 'application/xml' not supported for bodyType=java.lang.Object
Reviewed similar question at SpringBoot Webflux cannot return application/xml and javax.xml.bind.JAXBException Implementation of JAXB-API has not been found on module path or classpath, accordingly changed my code to use JAXB
JAXBContext jc = null;
try {
jc =JAXBContext.newInstance(new Class[]{com.apple.ist.realestate.sm.rqm.model.TestXml.class});
} catch (JAXBException e1) {
e1.printStackTrace();
}
return ServerResponse.ok().contentType(MediaType.APPLICATION_XML).body(BodyInserters.fromValue(jc));
Still I get the unsupported error: Content type 'application/xml' not supported for bodyType=com.sun.xml.bind.v2.runtime.JAXBContextImpl
Any help or discussion appreciated.