From 38f7dc6a6db31c55d0666d0745f45d8bc4b25cbf Mon Sep 17 00:00:00 2001 From: Davide Vacca Date: Thu, 17 Oct 2024 18:38:30 +0200 Subject: [PATCH] Recraft oneof java template --- .../templates/libraries/okhttp-gson/oneof_model.mustache | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/generators/java/okhttp-gson/templates/libraries/okhttp-gson/oneof_model.mustache b/generators/java/okhttp-gson/templates/libraries/okhttp-gson/oneof_model.mustache index f3d49dde..7c00259b 100644 --- a/generators/java/okhttp-gson/templates/libraries/okhttp-gson/oneof_model.mustache +++ b/generators/java/okhttp-gson/templates/libraries/okhttp-gson/oneof_model.mustache @@ -84,6 +84,7 @@ public class {{classname}} extends AbstractOpenApiSchema{{#vendorExtensions.x-im // check if the actual instance is of the type `{{{dataType}}}` if (value.getActualInstance() instanceof {{#isArray}}List{{/isArray}}{{#isMap}}Map{{/isMap}}{{^isMap}}{{^isArray}}{{{dataType}}}{{/isArray}}{{/isMap}}) { {{#isPrimitiveType}} + {{^isMap}} {{! Updated code - BEGIN }} {{#isArray}} JsonElement element = adapter{{#sanitizeGeneric}}{{{dataType}}}{{/sanitizeGeneric}}.toJsonTree(({{{dataType}}})value.getActualInstance()); @@ -94,6 +95,12 @@ public class {{classname}} extends AbstractOpenApiSchema{{#vendorExtensions.x-im elementAdapter.write(out, element); {{! Updated code - END }} return; + {{/isMap}} + {{#isMap}} + JsonObject object = adapter{{#sanitizeGeneric}}{{{dataType}}}{{/sanitizeGeneric}}.toJsonTree(({{{dataType}}})value.getActualInstance()).getAsJsonObject(); + elementAdapter.write(out, object); + return; + {{/isMap}} {{/isPrimitiveType}} {{^isPrimitiveType}} {{#isArray}} @@ -380,7 +387,7 @@ public class {{classname}} extends AbstractOpenApiSchema{{#vendorExtensions.x-im * @throws ClassCastException if the instance is not `{{{dataType}}}` */ {{! Suppress unchecked cast warning }} - {{! @SuppressWarnings("unchecked") }} + @SuppressWarnings("unchecked") public {{{dataType}}} get{{#sanitizeGeneric}}{{{dataType}}}{{/sanitizeGeneric}}() throws ClassCastException { return ({{{dataType}}})super.getActualInstance(); }