Skip to content

[BUG] Regression Java Native Template no longer able to process binary responses. #20634

@AlexanderSchuetz97

Description

@AlexanderSchuetz97

Hello in the java native template using the most recent version of the openapi generator (7.11.0) we can no longer process binary files.

In an endpoint the generator creates the following code:

        String responseBody = new String(localVarResponse.body().readAllBytes());
        localVarResponse.body().close();

        return new ApiResponse<File>(
            localVarResponse.statusCode(),
            localVarResponse.headers().map(),
            responseBody.isBlank()? null: memberVarObjectMapper.readValue(responseBody, new TypeReference<File>() {})
        );

As one can see the body is passed unconditionally into the String constructor. This was not the case previously.

In the previous version (7.10.0) the generator generated the following code

        return new ApiResponse<File>(
          localVarResponse.statusCode(),
          localVarResponse.headers().map(),
          localVarResponse.body() == null ? null : memberVarObjectMapper.readValue(localVarResponse.body(), new TypeReference<File>() {}) // closes the InputStream
        );

File being java.io.File, which is the correct type for binary data.

memberVarObjectMapper is set to a custom implementation of Object mapper via the generated setter that can handle java.io.File.
Unfortunately my files are not valid utf-8 (they are binary files like .zip's or images) and turning them into a utf-8 string destroys the data.

Also I used to be able to download very large files (100GB+) using the body inputstream. calling readAllBytes() on a 100GB+ file is deadly (OOM guaranteed)

Would it be possible to roll back this change please?
I don't really see any benefit to the new "template" other than that it destroys our ability to customize reading the response body.
Not everyone calls just "JSON" endpoints.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions