Skip to content

Commit

Permalink
Recraft oneof java template
Browse files Browse the repository at this point in the history
  • Loading branch information
dvacca-onfido committed Oct 17, 2024
1 parent 06c4df7 commit 38f7dc6
Showing 1 changed file with 8 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -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());
Expand All @@ -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}}
Expand Down Expand Up @@ -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();
}
Expand Down

0 comments on commit 38f7dc6

Please sign in to comment.