{"record":{"id":"9fef0e70d3b4f869","repo":"flowable/flowable-engine","slug":"converter-can-only-convert-string-to-date","errorCode":null,"errorMessage":"Converter can only convert string to date","messagePattern":"Converter can only convert string to date","errorType":"validation","errorClass":"FlowableIllegalArgumentException","httpStatus":400,"severity":"error","filePath":"modules/flowable-common-rest/src/main/java/org/flowable/common/rest/variable/DateRestVariableConverter.java","lineNumber":41,"sourceCode":" * @author Frederik Heremans\n */\npublic class DateRestVariableConverter implements RestVariableConverter {\n\n    @Override\n    public String getRestTypeName() {\n        return \"date\";\n    }\n\n    @Override\n    public Class<?> getVariableType() {\n        return Date.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 string to date\");\n            }\n            try {\n                return RequestUtil.parseLongDate((String) result.getValue());\n            } catch (DateTimeParseException e) {\n                throw new FlowableIllegalArgumentException(\"The given variable value is not a date: '\" + result.getValue() + \"'\", e);\n            }\n        }\n        return null;\n    }\n\n    @Override\n    public void convertVariableValue(Object variableValue, EngineRestVariable result) {\n        if (variableValue != null) {\n            if (!(variableValue instanceof Date dateValue)) {\n                throw new FlowableIllegalArgumentException(\"Converter can only convert booleans\");\n            }\n            result.setValue(dateValue.toInstant().toString());\n        } else {","sourceCodeStart":23,"sourceCodeEnd":59,"githubUrl":"https://github.com/flowable/flowable-engine/blob/d6d39ce1c69ff244f2d9dc6af756a9b95e865586/modules/flowable-common-rest/src/main/java/org/flowable/common/rest/variable/DateRestVariableConverter.java#L23-L59","documentation":"DateRestVariableConverter expects the REST variable's value to be a String containing a date in the long/timestamp format parsed by RequestUtil.parseLongDate. If the value is not a String, the converter cannot even attempt parsing, so FlowableIllegalArgumentException 'Converter can only convert string to date' is thrown before parsing.","triggerScenarios":"getVariableValue invoked on an EngineRestVariable whose value is a non-String (e.g. a Number/Long object or JSON number deserialized as Integer) while this date converter was selected for the variable.","commonSituations":"Clients sending epoch-millis as a JSON number instead of a string for date variables; type mapping selecting the date converter for non-string payloads; custom code stuffing pre-parsed Date objects into EngineRestVariable.","solutions":["Send date variable values as strings, e.g. \"1694044800000\" (long millis as string), matching the converter's expected format.","Check the REST variable 'type' so numeric values are handled by the appropriate converter rather than the date one.","If you build EngineRestVariable yourself, set value to a String: String.valueOf(timestamp).","For other date formats, convert client-side to epoch millis string before sending (parseLongDate accepts epoch millis)."],"exampleFix":"// before\nrestVariable.setValue(1694044800000L); // Long -> throws\n// after\nrestVariable.setValue(String.valueOf(1694044800000L)); // epoch millis as string","handlingStrategy":"type-guard","validationCode":"if (value != null && !(value instanceof String)) {\n    value = String.valueOf(value); // epoch millis number -> string\n}","typeGuard":"String asDateString(Object v) {\n    if (v instanceof String) return (String) v;\n    if (v instanceof Number) return String.valueOf(v.longValue());\n    return null;\n}","tryCatchPattern":"try {\n    Object v = converter.getVariableValue(restVariable);\n} catch (FlowableIllegalArgumentException e) {\n    if (e.getMessage() != null && e.getMessage().contains(\"convert string to date\")) {\n        throw new IllegalArgumentException(\"Date variables must be epoch-millis strings, got: \" + restVariable.getValue(), e);\n    }\n    throw e;\n}","preventionTips":["Send date variables as epoch-millis strings, not JSON numbers or Date objects.","Confirm the variable 'type' maps to the date converter only for string values.","Coerce numeric timestamps to strings before populating EngineRestVariable.","Share a client-side date serialization helper so all date variables use one valid format."],"tags":["rest","variables","type-mismatch","date"],"backgroundTag":"type-mismatch","analyzedSha":"d6d39ce1c69ff244f2d9dc6af756a9b95e865586","analyzedAt":"2026-09-11T06:41:19.413Z","contentChangedAt":"2026-09-11T06:41:19.413Z","schemaVersion":2},"datasetVersion":"2026-09-14T05:17:10.506Z"}