{"record":{"id":"4f0128d481b01064","repo":"flowable/flowable-engine","slug":"model-value-should-be-a-string","errorCode":null,"errorMessage":"Model value should be a String","messagePattern":"Model value should be a String","errorType":"validation","errorClass":"FlowableIllegalArgumentException","httpStatus":null,"severity":"error","filePath":"modules/flowable-engine/src/main/java/org/flowable/engine/impl/form/EnumFormType.java","lineNumber":57,"sourceCode":"    @Override\n    public Object getInformation(String key) {\n        if (\"values\".equals(key)) {\n            return values;\n        }\n        return null;\n    }\n\n    @Override\n    public Object convertFormValueToModelValue(String propertyValue) {\n        validateValue(propertyValue);\n        return propertyValue;\n    }\n\n    @Override\n    public String convertModelValueToFormValue(Object modelValue) {\n        if (modelValue != null) {\n            if (!(modelValue instanceof String)) {\n                throw new FlowableIllegalArgumentException(\"Model value should be a String\");\n            }\n            validateValue((String) modelValue);\n        }\n        return (String) modelValue;\n    }\n\n    protected void validateValue(String value) {\n        if (value != null) {\n            if (values != null && !values.containsKey(value)) {\n                throw new FlowableIllegalArgumentException(\"Invalid value for enum form property: \" + value);\n            }\n        }\n    }\n\n}\n","sourceCodeStart":39,"sourceCodeEnd":73,"githubUrl":"https://github.com/flowable/flowable-engine/blob/d6d39ce1c69ff244f2d9dc6af756a9b95e865586/modules/flowable-engine/src/main/java/org/flowable/engine/impl/form/EnumFormType.java#L39-L73","documentation":"EnumFormType represents a form property with a fixed set of allowed values. convertModelValueToFormValue requires the model value to be a Java String; any other type is rejected with FlowableIllegalArgumentException 'Model value should be a String'. After the type check it also validates the value is one of the configured enum values.","triggerScenarios":"Rendering/submitting a form where the variable bound to an enum form property is a non-String type (e.g. Integer code, custom enum object, Long) instead of the String key of the enum value.","commonSituations":"Storing enum keys as integers from external systems, mapping a Java enum directly into the variable without .name(), refactor that changed the variable type.","solutions":["Set the variable as a String matching one of the enum form values (e.g. myJavaEnum.name()).","Convert non-string keys at the boundary: String.valueOf or a lookup map from code to key.","Change the form type in the BPMN if numeric codes are intended.","Add a conversion step in custom form rendering before FormService calls."],"exampleFix":"// before\nruntimeService.setVariable(executionId, \"priority\", 3); // Integer\n// after\nruntimeService.setVariable(executionId, \"priority\", Priority.fromCode(3).name()); // String key","handlingStrategy":"type-guard","validationCode":"Object v = runtimeService.getVariable(executionId, name);\nif (v != null && !(v instanceof String)) {\n    throw new IllegalArgumentException(\"Enum form variable '\" + name + \"' must be a String key\");\n}","typeGuard":"static boolean isEnumFormValue(Object v) {\n    return v == null || v instanceof String;\n}","tryCatchPattern":"try {\n    formService.submitTaskFormData(taskId, properties);\n} catch (FlowableIllegalArgumentException e) {\n    if (\"Model value should be a String\".equals(e.getMessage())) {\n        properties.put(enumField, String.valueOf(rawValues.get(enumField)));\n        formService.submitTaskFormData(taskId, properties);\n    } else { throw e; }\n}","preventionTips":["Store enum keys as String (use JavaEnum.name()) in process variables.","Convert numeric codes to string keys at the API boundary.","Document that enum form properties hold String keys.","Cover form rendering of enum variables in integration tests."],"tags":["flowable","forms","type-mismatch","enum"],"backgroundTag":"type-mismatch","analyzedSha":"d6d39ce1c69ff244f2d9dc6af756a9b95e865586","analyzedAt":"2026-09-11T06:41:19.413Z","contentChangedAt":"2026-09-11T06:41:19.413Z","schemaVersion":2},"datasetVersion":"2026-09-18T11:17:12.947Z"}