From 30ee3f343eb681514ce5b33438de3b8f4fb1f50b Mon Sep 17 00:00:00 2001 From: Luis Ballabeni Date: Tue, 5 May 2020 01:40:22 -0400 Subject: [PATCH] Fix #6157: Updated native template to fix null async return (#6168) * Fix #6157: Updated native template to fix null async return Should fix issue: https://github.com/OpenAPITools/openapi-generator/issues/6157 * fixed uncaught json exception in java native api gen * cleaning up Co-authored-by: Luis Ballabeni --- .../Java/libraries/native/api.mustache | 20 +++++++++++-------- 1 file changed, 12 insertions(+), 8 deletions(-) diff --git a/modules/openapi-generator/src/main/resources/Java/libraries/native/api.mustache b/modules/openapi-generator/src/main/resources/Java/libraries/native/api.mustache index 23388d36a76..7d6ed2d4bb7 100644 --- a/modules/openapi-generator/src/main/resources/Java/libraries/native/api.mustache +++ b/modules/openapi-generator/src/main/resources/Java/libraries/native/api.mustache @@ -180,14 +180,18 @@ public class {{classname}} { localVarResponse.body()) ); } else { - return CompletableFuture.completedFuture( - {{#returnValue}} - memberVarObjectMapper.readValue(localVarResponse.body(), new TypeReference<{{{returnType}}}>() {}) - {{/returnValue}} - {{^returnValue}} - null - {{/returnValue}} - ); + try { + return CompletableFuture.completedFuture( + {{#returnType}} + memberVarObjectMapper.readValue(localVarResponse.body(), new TypeReference<{{{returnType}}}>() {}) + {{/returnType}} + {{^returnType}} + null + {{/returnType}} + ); + } catch (IOException e) { + return CompletableFuture.failedFuture(new ApiException(e)); + } } }); {{/asyncNative}}