{"record":{"id":"602e91b4a2d19fbc","repo":"OpenAPITools/openapi-generator","slug":"must-be-one-of-non-null-non-empty-non-defaul","errorCode":null,"errorMessage":"{} must be one of [NON_NULL, NON_EMPTY, NON_DEFAULT, NONE] but was: {}","messagePattern":"(.+?) must be one of \\[NON_NULL, NON_EMPTY, NON_DEFAULT, NONE\\] but was: (.+?)","errorType":"exception","errorClass":"IllegalArgumentException","httpStatus":null,"severity":"error","filePath":"modules/openapi-generator/src/main/java/org/openapitools/codegen/utils/JsonAnnotationPolicyUtils.java","lineNumber":116,"sourceCode":"     * @param policy      the raw config option value (may be {@code null}, in which case the default\n     *                    {@code NON_NULL} is returned)\n     * @param optionName  the config option name, used in the error message (kept generator-agnostic)\n     * @return the normalized (upper-case) policy name: one of {@code NON_NULL}, {@code NON_EMPTY},\n     * {@code NON_DEFAULT}, {@code NONE}.\n     * @throws IllegalArgumentException when the value is not one of the supported policies.\n     */\n    public static String normalizeJsonIncludePolicy(String policy, String optionName) {\n        if (policy == null) {\n            return JsonIncludePolicy.NON_NULL.name();\n        }\n        JsonIncludePolicy parsed;\n        try {\n            parsed = JsonIncludePolicy.valueOf(policy.trim().toUpperCase(java.util.Locale.ROOT));\n        } catch (IllegalArgumentException e) {\n            parsed = null;\n        }\n        if (parsed == null || !parsed.isValidOptionalNonNullPolicy()) {\n            throw new IllegalArgumentException(optionName\n                    + \" must be one of \" + JsonIncludePolicy.OPTIONAL_NON_NULL_POLICIES + \" but was: \" + policy);\n        }\n        return parsed.name();\n    }\n\n    /**\n     * Read back the {@code optionalNonNullPropertyJsonInclude} config option from {@code additionalProperties},\n     * validating/normalizing it via {@link #normalizeJsonIncludePolicy}. Returns {@code current} unchanged when\n     * the option was not present in {@code additionalProperties} (i.e. the generator's existing/default value is\n     * kept). Callers are responsible for writing the resolved value back via their own\n     * {@code writePropertyBack}/{@code additionalProperties.put} convention.\n     *\n     * @param additionalProperties the generator's additional properties map\n     * @param current               the generator's current {@code optionalNonNullPropertyJsonInclude} value\n     * @return the resolved {@link JsonIncludePolicy} to assign to the generator's field\n     */\n    public static JsonIncludePolicy resolveOptionalNonNullPropertyJsonInclude(Map<String, Object> additionalProperties, JsonIncludePolicy current) {\n        if (!additionalProperties.containsKey(CodegenConstants.OPTIONAL_NON_NULL_PROPERTY_JSON_INCLUDE)) {","sourceCodeStart":98,"sourceCodeEnd":134,"githubUrl":"https://github.com/OpenAPITools/openapi-generator/blob/fcec517be3cf5b7964296bcba25fbc97541484e7/modules/openapi-generator/src/main/java/org/openapitools/codegen/utils/JsonAnnotationPolicyUtils.java#L98-L134","documentation":"JsonAnnotationPolicyUtils.normalizeJsonIncludePolicy validates the spring/kotlin-spring option 'optionalNonNullPropertyJsonInclude', which sets the @JsonInclude policy emitted for optional, non-nullable model properties. Unlike the per-property extension, this option accepts only a subset: NON_NULL, NON_EMPTY, NON_DEFAULT, or NONE (no annotation). Other JsonInclude constants (ALWAYS, NON_ABSENT, USE_DEFAULTS, CUSTOM) and any unrecognized string throw IllegalArgumentException.","triggerScenarios":"Generating with -g spring -DoptionalNonNullPropertyJsonInclude=ALWAYS, =USE_DEFAULTS, or a typo like =NON-NULL. The value is trimmed and upper-cased before matching, so casing is forgiving but the token must be one of the four allowed names.","commonSituations":"Assuming every JsonInclude.Include value is accepted because the sibling extension supports them; migrating Jackson global defaults (spring.jackson.default-property-inclusion) verbatim into this generator option; values copied from documentation of a different generator version.","solutions":["Pick one of NON_NULL (the default), NON_EMPTY, NON_DEFAULT, or NONE.","If you need ALWAYS/NON_ABSENT/USE_DEFAULTS/CUSTOM semantics for specific properties, set x-jackson-json-include-policy per property in the spec instead of this global option.","Re-run; the message echoes the offending value — fix exactly that key in your -D args or config file."],"exampleFix":"# before\nopenapi-generator-cli generate -g spring \\\n  -DoptionalNonNullPropertyJsonInclude=ALWAYS\n\n# after\nopenapi-generator-cli generate -g spring \\\n  -DoptionalNonNullPropertyJsonInclude=NON_NULL","handlingStrategy":"validation","validationCode":"case \"$(printf '%s' \"$OPT_NONNULL_JSON_INCLUDE\" | tr '[:lower:]' '[:upper:]' | tr -d ' ')\" in\n  NON_NULL|NON_EMPTY|NON_DEFAULT|NONE|\"\") ;;\n  *) echo \"ERROR: optionalNonNullPropertyJsonInclude must be NON_NULL, NON_EMPTY, NON_DEFAULT or NONE\" >&2; exit 1;;\nesac","typeGuard":"const OPTIONAL_NON_NULL_POLICIES = ['NON_NULL','NON_EMPTY','NON_DEFAULT','NONE'] as const;\ntype OptionalNonNullPolicy = typeof OPTIONAL_NON_NULL_POLICIES[number];\nconst isOptionalNonNullPolicy = (v: string): v is OptionalNonNullPolicy =>\n  (OPTIONAL_NON_NULL_POLICIES as readonly string[]).includes(v.trim().toUpperCase());","tryCatchPattern":null,"preventionTips":["This option is a subset — only 4 values; per-property overrides are the place for the other enum constants.","Default the option to NON_NULL and only change it deliberately."],"tags":["jackson","spring","codegen","config-validation"],"backgroundTag":"invalid-option-value","analyzedSha":"fcec517be3cf5b7964296bcba25fbc97541484e7","analyzedAt":"2026-08-22T11:13:11.613Z","schemaVersion":2},"datasetVersion":"2026-08-22T14:17:55.899Z"}