我有一个使用Swagger codegen为后端API创建的Java客户端sdk . 我需要在Android应用程序中使用它 .

后端开发人员定义了ErrorResponse模型,我可以在生成的代码中看到这些模型类 . 但我认为无法读取反序列化为相应类型的错误响应 .

以下是我的代码

new DefaultApi().loginAsync(loginRequest, new ApiCallback<LoginSuccessResponse>() {
        @Override
        public void onFailure(ApiException e, int statusCode, Map<String, List<String>> responseHeaders) {
            String responseBody = e.getResponseBody();
            //I can access the response body as string.
            //Is it possible to access the response body as an object corresponding the model
        }

        @Override
        public void onSuccess(LoginSuccessResponse result, int statusCode, Map<String, List<String>> responseHeaders) {
            LoginSuccessResponse iCanGetTheSuccessResultHere = result;
        }

        @Override
        public void onUploadProgress(long bytesWritten, long contentLength, boolean done) {

        }

        @Override
        public void onDownloadProgress(long bytesRead, long contentLength, boolean done) {

        }
    })

如果失败,我可以作为字符串访问响应正文 . 是否可以作为对应模型的对象访问响应主体 .

在生成的代码中,我可以看到类似'LoginFailedResponse'和'ErrorResponse'的类,但不知道如何将响应读作这些类型之一 .