{"record":{"id":"75b45005f8480d86","repo":"flowable/flowable-engine","slug":"converter-can-only-convert-longs","errorCode":null,"errorMessage":"Converter can only convert longs","messagePattern":"Converter can only convert longs","errorType":"validation","errorClass":"FlowableIllegalArgumentException","httpStatus":400,"severity":"error","filePath":"modules/flowable-common-rest/src/main/java/org/flowable/common/rest/variable/LongRestVariableConverter.java","lineNumber":37,"sourceCode":" * @author Frederik Heremans\n */\npublic class LongRestVariableConverter implements RestVariableConverter {\n\n    @Override\n    public String getRestTypeName() {\n        return \"long\";\n    }\n\n    @Override\n    public Class<?> getVariableType() {\n        return Long.class;\n    }\n\n    @Override\n    public Object getVariableValue(EngineRestVariable result) {\n        if (result.getValue() != null) {\n            if (!(result.getValue() instanceof Number)) {\n                throw new FlowableIllegalArgumentException(\"Converter can only convert longs\");\n            }\n            return ((Number) result.getValue()).longValue();\n        }\n        return null;\n    }\n\n    @Override\n    public void convertVariableValue(Object variableValue, EngineRestVariable result) {\n        if (variableValue != null) {\n            if (!(variableValue instanceof Long)) {\n                throw new FlowableIllegalArgumentException(\"Converter can only convert integers\");\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/LongRestVariableConverter.java#L19-L55","documentation":"LongRestVariableConverter.getVariableValue converts a REST variable into a java.lang.Long and requires the REST value to be a Number. If the value is any other type it throws FlowableIllegalArgumentException, since only numeric JSON values can be narrowed via Number.longValue().","triggerScenarios":"Sending a variable of REST type long whose value is a String (e.g. \"123\"), boolean, array, or object, so result.getValue() fails the Number instanceof check in getVariableValue.","commonSituations":"Clients posting numeric IDs as quoted strings; form/query inputs kept as text; JSON frameworks that deserialize numbers into Strings or BigDecimal wrappers unexpectedly (BigDecimal is fine, but String is not).","solutions":["Send the value as an unquoted JSON number (e.g. 123, not \"123\").","Parse numeric strings with Long.parseLong client-side before posting.","Verify the REST variable type marker matches the payload (integer vs long vs string).","Fix client serialization that quotes all values (e.g. Map<String, String> payloads)."],"exampleFix":"// before\n{ \"type\": \"long\", \"value\": \"123\" }\n\n// after\n{ \"type\": \"long\", \"value\": 123 }","handlingStrategy":"validation","validationCode":"if (!(rawValue instanceof Number)) {\n    throw new IllegalArgumentException(\"long variable must be a JSON number, got: \"\n        + (rawValue == null ? \"null\" : rawValue.getClass().getSimpleName()));\n}","typeGuard":"static boolean isNumeric(Object v) {\n    return v instanceof Number;\n}","tryCatchPattern":"try {\n    Object value = converter.getVariableValue(restVar);\n} catch (FlowableIllegalArgumentException e) {\n    log.error(\"long variable value is not numeric: {}\", restVar.getValue(), e);\n}","preventionTips":["Post IDs and counts as unquoted JSON numbers.","Parse numeric strings with Long.parseLong on the client before sending.","Use typed clients/DTOs with long fields so serialization preserves numeric JSON."],"tags":["long","rest-variable","type-mismatch","number"],"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"}