diff --git a/dsl/src/cli/java-rest-client-jdk/shared.ts b/dsl/src/cli/java-rest-client-jdk/shared.ts index 5de0bb8..ca0baf6 100644 --- a/dsl/src/cli/java-rest-client-jdk/shared.ts +++ b/dsl/src/cli/java-rest-client-jdk/shared.ts @@ -125,6 +125,11 @@ export function generateBuilderProperty(node: IndentNode, property: MKeyProperty node.append('@Override', NL) node.append(`public ${typePrefix ? `${typePrefix}.`: ''}Builder ${property.name}(${toType(property, artifactConfig, fqn)} ${property.name}) {`, NL) node.indent( methodBody => { + if( property.optional && ! property.nullable && ( isMBuiltinType(property.type) && ! isJavaPrimitive(property.type) ) ) { + methodBody.append(`if( ${property.name} == null ) {`, NL); + methodBody.indent( block => block.append('return this;', NL)) + methodBody.append('}',NL); + } if( property.array ) { if( property.variant === 'builtin' && isMBuiltinType(property.type) ) { methodBody.append(`${builtinBuilderArrayJSONAccess({ type: property.type, name: property.name })});`, NL) @@ -180,3 +185,16 @@ export function builtinBuilderAccess(property: { type: MBuiltinType, name: strin return `$builder.add("${property.name}", ${property.name}.toString())`; } } + +function isJavaPrimitive(type: MBuiltinType) { + switch(type) { + case 'boolean': + case 'double': + case 'float': + case 'int': + case 'long': + case 'short': + return true; + } + return false; +}