{"record":{"id":"2f1c119dce43e696","repo":"flowable/flowable-engine","slug":"converter-can-only-convert-strings","errorCode":null,"errorMessage":"Converter can only convert strings","messagePattern":"Converter can only convert strings","errorType":"validation","errorClass":"FlowableIllegalArgumentException","httpStatus":400,"severity":"error","filePath":"modules/flowable-common-rest/src/main/java/org/flowable/common/rest/variable/StringRestVariableConverter.java","lineNumber":37,"sourceCode":" * @author Frederik Heremans\n */\npublic class StringRestVariableConverter implements RestVariableConverter {\n\n    @Override\n    public String getRestTypeName() {\n        return \"string\";\n    }\n\n    @Override\n    public Class<?> getVariableType() {\n        return String.class;\n    }\n\n    @Override\n    public Object getVariableValue(EngineRestVariable result) {\n        if (result.getValue() != null) {\n            if (!(result.getValue() instanceof String)) {\n                throw new FlowableIllegalArgumentException(\"Converter can only convert strings\");\n            }\n            return result.getValue();\n        }\n        return null;\n    }\n\n    @Override\n    public void convertVariableValue(Object variableValue, EngineRestVariable result) {\n        if (variableValue != null) {\n            if (!(variableValue instanceof String)) {\n                throw new FlowableIllegalArgumentException(\"Converter can only convert strings\");\n            }\n            result.setValue(variableValue);\n        } else {\n            result.setValue(null);\n        }\n    }\n","sourceCodeStart":19,"sourceCodeEnd":55,"githubUrl":"https://github.com/flowable/flowable-engine/blob/d6d39ce1c69ff244f2d9dc6af756a9b95e865586/modules/flowable-common-rest/src/main/java/org/flowable/common/rest/variable/StringRestVariableConverter.java#L19-L55","documentation":"StringRestVariableConverter.getVariableValue returns the raw REST variable value, which must already be a java.lang.String. If the value in EngineRestVariable is any other type, the converter throws FlowableIllegalArgumentException because it cannot represent it as a string variable.","triggerScenarios":"Calling getVariableValue on an EngineRestVariable whose value is a non-String object (e.g. Integer, Map, byte[]) while the string converter is resolved for that variable's REST type name.","commonSituations":"A variable persisted as one type but labeled/requested as string in REST; custom serialization placing non-String values in the string converter's slot; test code constructing EngineRestVariable with wrong types.","solutions":["Make sure the value placed in EngineRestVariable for a string variable is actually a String.","Fix the variable type registration so non-string values route to their proper converter.","Convert the value to String explicitly before assigning it to the REST variable."],"exampleFix":"// before\nresult.setValue(123); // Integer in string converter path\n// after\nresult.setValue(String.valueOf(123));","handlingStrategy":"type-guard","validationCode":"if (result.getValue() != null && !(result.getValue() instanceof String)) {\n    throw new IllegalArgumentException(\"Expected String value for string variable\");\n}","typeGuard":"static boolean isString(Object v) { return v instanceof String; }","tryCatchPattern":"try {\n    Object v = converter.getVariableValue(result);\n} catch (FlowableIllegalArgumentException e) {\n    // route to the correct converter based on result.getValue().getClass()\n}","preventionTips":["Only place String values in string-typed REST variables.","Use the RestResponseFactory type resolution instead of manual converter selection.","Add assertions in tests that variable types match their REST type names."],"tags":["type-mismatch","rest-variable","conversion"],"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"}