'How to convert OpenAPI3 upload body String to byte array in Java

in my Spring Boot project, I use an OpenAPI 3 file to generate Java class, for file upload (not Multipart Requests).

Here is a part of my describe file:

  requestBody:
    description: content
    required: true
    content:
      application/octet-stream:
        schema:
          type: string
          format: binary
          description: content

The Controller class:

@Override
    public ResponseEntity<Object> updateContent(String version, String body) throws Exception {
...

The request body is an uploaded zip file, I want to convert the body from String to byte array. How can I do it in Java? Thanks.



Sources

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

Source: Stack Overflow

Solution Source