{"record":{"id":"474e4dc4fe4e9007","repo":"flowable/flowable-engine","slug":"model-value-should-be-a-string-474e4d","errorCode":null,"errorMessage":"Model value should be a String","messagePattern":"Model value should be a String","errorType":"validation","errorClass":"ActivitiIllegalArgumentException","httpStatus":null,"severity":"error","filePath":"modules/flowable5-engine/src/main/java/org/activiti/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 ActivitiIllegalArgumentException(\"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 ActivitiIllegalArgumentException(\"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/flowable5-engine/src/main/java/org/activiti/engine/impl/form/EnumFormType.java#L39-L73","documentation":"Thrown by EnumFormType.convertModelValueToFormValue when a form property of type 'enum' has a non-null model value that is not a String, while enum values are stored/compared as strings (keys of the configured values map). The ActivitiIllegalArgumentException guards the cast to String before validateValue is called.","triggerScenarios":"Rendering a form with an enum property whose process variable holds a non-String value — e.g. an Integer code, an enum Java constant, or a JSON-deserialized number — and the engine converts the model value to its form representation.","commonSituations":"Setting variables from REST/JSON where the client sends numbers for enum keys; using Java enum constants as variable values; CSV/DB imports writing numeric codes into enum-typed variables.","solutions":["Store the enum key as a String variable matching one of the keys in the form's values map.","Convert before assignment: variables.put(\"priority\", myEnum.name()) or String.valueOf(code).","If values must be non-strings, write a custom FormType that handles the conversion.","Fix serialization in front-ends/scripts so enum properties are submitted as strings."],"exampleFix":"// before\nvariables.put(\"priority\", 2); // Integer\n// after\nvariables.put(\"priority\", \"high\"); // String key from the enum values map","handlingStrategy":"type-guard","validationCode":"Object v = variables.get(\"priority\");\nif (v != null && !(v instanceof String)) {\n    throw new IllegalArgumentException(\"enum variable 'priority' must be a String key\");\n}","typeGuard":"boolean isEnumKeyValue(Object v) {\n    return v == null || v instanceof String;\n}","tryCatchPattern":"try {\n    formService.getTaskFormData(taskId);\n} catch (org.activiti.engine.ActivitiIllegalArgumentException e) {\n    if (e.getMessage().equals(\"Model value should be a String\")) {\n        runtimeService.setVariable(executionId, \"priority\", String.valueOf(rawValue));\n    }\n}","preventionTips":["Store enum form values as String keys, never Integer codes or Java enum constants.","Use myEnum.name() when converting Java enums to variables.","Enforce string types for enum fields in REST DTOs."],"tags":["forms","enum","type-mismatch","validation"],"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"}