From 812712a9f1ae321b63bbf2b02c2fc19bc94b6cff Mon Sep 17 00:00:00 2001 From: Eddie Chayes <35413716+eddiechayes@users.noreply.github.com> Date: Wed, 28 Aug 2024 14:40:14 -0700 Subject: [PATCH] fix json validation for fields that are required but nullable (#781) --- .../resources/Java/libraries/okhttp-gson/pojo.mustache | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/generator/konfig-generator-api/src/main/resources/Java/libraries/okhttp-gson/pojo.mustache b/generator/konfig-generator-api/src/main/resources/Java/libraries/okhttp-gson/pojo.mustache index 13c2f0771..592208c05 100644 --- a/generator/konfig-generator-api/src/main/resources/Java/libraries/okhttp-gson/pojo.mustache +++ b/generator/konfig-generator-api/src/main/resources/Java/libraries/okhttp-gson/pojo.mustache @@ -558,7 +558,14 @@ public class {{classname}} {{#parent}}extends {{{.}}} {{/parent}}{{#vendorExtens {{^isNestedPrimitive}} {{#required}} // validate the required field `{{{baseName}}}` + {{#isNullable}} + if (!jsonObj.get("{{{baseName}}}").isJsonNull()) { + {{{dataType}}}.validateJsonObject(jsonObj.getAsJsonObject("{{{baseName}}}")); + } + {{/isNullable}} + {{^isNullable}} {{{dataType}}}.validateJsonObject(jsonObj.getAsJsonObject("{{{baseName}}}")); + {{/isNullable}} {{/required}} {{^required}} // validate the optional field `{{{baseName}}}`