{"record":{"id":"3b89a7e143ecdcf4","repo":"flowable/flowable-engine","slug":"error-converting-request-body-to-restvariable-inst-3b89a7","errorCode":null,"errorMessage":"Error converting request body to RestVariable instance","messagePattern":"Error converting request body to RestVariable instance","errorType":"http","errorClass":"FlowableIllegalArgumentException","httpStatus":400,"severity":"error","filePath":"modules/flowable-rest/src/main/java/org/flowable/rest/service/api/runtime/task/TaskVariableResource.java","lineNumber":117,"sourceCode":"\n        Task task = getTaskFromRequestWithoutAccessCheck(taskId);\n\n        RestVariable result = null;\n        if (request instanceof MultipartHttpServletRequest) {\n            result = setBinaryVariable((MultipartHttpServletRequest) request, task, false);\n\n            if (!result.getName().equals(variableName)) {\n                throw new FlowableIllegalArgumentException(\"Variable name in the body should be equal to the name used in the requested URL.\");\n            }\n\n        } else {\n\n            RestVariable restVariable = null;\n\n            try {\n                restVariable = objectMapper.readValue(request.getInputStream(), RestVariable.class);\n            } catch (Exception e) {\n                throw new FlowableIllegalArgumentException(\"Error converting request body to RestVariable instance\", e);\n            }\n\n            if (restVariable == null) {\n                throw new FlowableException(\"Invalid body was supplied\");\n            }\n            if (!restVariable.getName().equals(variableName)) {\n                throw new FlowableIllegalArgumentException(\"Variable name in the body should be equal to the name used in the requested URL.\");\n            }\n\n            result = setSimpleVariable(restVariable, task, false);\n        }\n        return result;\n    }\n\n    @ApiOperation(value = \"Delete a variable on a task\", tags = { \"Task Variables\" }, nickname = \"deleteTaskInstanceVariable\", code = 204)\n    @ApiImplicitParams(@ApiImplicitParam(name = \"scope\", dataType = \"string\", value = \"Scope of variable to be returned. When local, only task-local variable value is returned. When global, only variable value from the task’s parent execution-hierarchy are returned. When the parameter is omitted, a local variable will be returned if it exists, otherwise a global variable.\", paramType = \"query\"))\n    @ApiResponses(value = {\n            @ApiResponse(code = 204, message = \"Indicates the task variable was found and has been deleted. Response-body is intentionally empty.\"),","sourceCodeStart":99,"sourceCodeEnd":135,"githubUrl":"https://github.com/flowable/flowable-engine/blob/d6d39ce1c69ff244f2d9dc6af756a9b95e865586/modules/flowable-rest/src/main/java/org/flowable/rest/service/api/runtime/task/TaskVariableResource.java#L99-L135","documentation":"For non-multipart PUT requests to update a task variable, Flowable deserializes the request body JSON into a RestVariable object with Jackson's ObjectMapper. FlowableIllegalArgumentException is thrown when the body cannot be parsed/converted (malformed JSON, wrong shape, encoding problems). The original exception is preserved as the cause.","triggerScenarios":"PUT /runtime/tasks/{taskId}/variables/{variableName} with a Content-Type other than multipart whose input stream is not valid JSON for RestVariable: malformed JSON, missing quotes, wrong content type (e.g. form-encoded), empty body, or JSON with incompatible fields.","commonSituations":"Sending form-urlencoded data instead of JSON; forgetting Content-Type: application/json; trailing commas or syntax errors; sending XML; empty PUT body.","solutions":["Send a valid JSON body shaped like RestVariable: {\"name\":\"var\",\"type\":\"string\",\"value\":\"x\"}.","Set header Content-Type: application/json on the request.","Validate the JSON with a linter or by deserializing client-side before sending.","Check the exception cause in server logs for the exact Jackson parse error."],"exampleFix":"// before (form-encoded, not JSON)\ncurl -X PUT .../tasks/123/variables/name -d 'value=John'\n\n// after\ncurl -X PUT -H 'Content-Type: application/json' .../tasks/123/variables/name -d '{\"name\":\"name\",\"type\":\"string\",\"value\":\"John\"}'","handlingStrategy":"validation","validationCode":"function buildVariablePayload(name, type, value) {\n  const payload = JSON.stringify({ name, type, value });\n  JSON.parse(payload); // throws early if serialization produced invalid JSON\n  return payload;\n}","typeGuard":"function isRestVariable(obj) {\n  return typeof obj === 'object' && obj !== null &&\n    typeof obj.name === 'string' &&\n    ('value' in obj) && typeof obj.type === 'string';\n}","tryCatchPattern":"try {\n  const resp = await fetch(url, { method: 'PUT', headers: {'Content-Type': 'application/json'}, body });\n  if (!resp.ok) throw new Error(await resp.text());\n} catch (e) {\n  if (String(e.message).includes('Error converting request body')) console.error('body was not valid RestVariable JSON:', body);\n  throw e;\n}","preventionTips":["Always send Content-Type: application/json for non-multipart variable updates.","Validate the JSON body against the RestVariable shape client-side before sending.","Never send form-encoded or XML bodies to the variable update endpoint.","Test payloads with a JSON linter in CI for API client code."],"tags":["rest-api","flowable","json","validation"],"backgroundTag":"json-parse-error","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"}