How do I define a REST endpoint that returns a PDF binary using SpringBoot REST in Java with Swagger annotations?
A lot of answers to similar questions use @RequestMapping, but I am using Swagger/OpenAPI annotations like @ApiResponse. On my resource method, should I indicate the content type with 2 annotations?
@ApiResponse(content = @Content(mediaType = "application/pdf", schema=@Schema(type="string", format="binary")))
@Produces("application/pdf")
When I try this and return a ResponseEntity<byte[]> or ResponseEntity< ByteArrayStream > like this:
return ResponseEntity.ok()
.contentType(org.springframework.http.MediaType.APPLICATION_PDF)
.cacheControl(CacheControl.noCache())
.header("Content-Disposition", "attachment; filename=" + "blah.pdf")
.body(contents);
I get the error:
MessageBodyWriter not found for media type=application/pdf
and is there somewhere to find clear documentation of this stuff? very hard to google for.