我有一个使用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”这样的类,但不知道如何将响应读作其中一种类型。