{"record":{"id":"d158a56b12a7177c","repo":"flowable/flowable-engine","slug":"converter-can-only-convert-localdatetime","errorCode":null,"errorMessage":"Converter can only convert localDateTime","messagePattern":"Converter can only convert localDateTime","errorType":"validation","errorClass":"FlowableIllegalArgumentException","httpStatus":400,"severity":"error","filePath":"modules/flowable-common-rest/src/main/java/org/flowable/common/rest/variable/LocalDateTimeRestVariableConverter.java","lineNumber":54,"sourceCode":"    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 localDateTime\");\n            }\n            try {\n                return LocalDateTime.parse((String) result.getValue());\n            } catch (DateTimeParseException e) {\n                throw new FlowableIllegalArgumentException(\"The given variable value is not a localDateTime: '\" + 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 LocalDateTime)) {\n                throw new FlowableIllegalArgumentException(\"Converter can only convert localDateTime\");\n            }\n            result.setValue(variableValue.toString());\n        } else {\n            result.setValue(null);\n        }\n    }\n\n}\n","sourceCodeStart":36,"sourceCodeEnd":63,"githubUrl":"https://github.com/flowable/flowable-engine/blob/d6d39ce1c69ff244f2d9dc6af756a9b95e865586/modules/flowable-common-rest/src/main/java/org/flowable/common/rest/variable/LocalDateTimeRestVariableConverter.java#L36-L63","documentation":"LocalDateTimeRestVariableConverter.convertVariableValue serializes engine variables to REST and requires the value to be a java.time.LocalDateTime. Any other non-null object fails the instanceof check and throws FlowableIllegalArgumentException, as only LocalDateTime can be written as a localDateTime REST variable.","triggerScenarios":"Calling convertVariableValue(value, result) with a non-null object that is not LocalDateTime (e.g. java.util.Date, ZonedDateTime, OffsetDateTime, Instant, String), typically when the engine variable's type is exposed as localDateTime via REST.","commonSituations":"Legacy java.util.Date variables surfaced as localDateTime; zoned types (ZonedDateTime/Instant) from calendars or external systems; String values never parsed into LocalDateTime.","solutions":["Convert the value to LocalDateTime (e.g. LocalDateTime.ofInstant(instant, zoneId)) before serialization.","Match the REST variable type to the actual Java type (use the appropriate converter for Date/ZonedDateTime).","Parse Strings with LocalDateTime.parse before conversion.","Migrate persisted legacy datetime variables to LocalDateTime."],"exampleFix":"// before\nconverter.convertVariableValue(Instant.now(), restVar); // throws\n\n// after\nLocalDateTime ldt = LocalDateTime.ofInstant(Instant.now(), ZoneId.systemDefault());\nconverter.convertVariableValue(ldt, restVar);","handlingStrategy":"type-guard","validationCode":"if (value instanceof LocalDateTime) {\n    converter.convertVariableValue(value, restVar);\n} else if (value instanceof java.util.Date d) {\n    converter.convertVariableValue(LocalDateTime.ofInstant(d.toInstant(), ZoneId.systemDefault()), restVar);\n} else {\n    throw new IllegalArgumentException(\"Cannot serialize as localDateTime: \" + value.getClass());\n}","typeGuard":"static boolean isLocalDateTime(Object v) {\n    return v instanceof java.time.LocalDateTime;\n}","tryCatchPattern":"try {\n    converter.convertVariableValue(value, restVar);\n} catch (FlowableIllegalArgumentException e) {\n    throw new IllegalStateException(\"localDateTime REST variable requires java.time.LocalDateTime, got: \"\n        + value.getClass().getName(), e);\n}","preventionTips":["Use java.time.LocalDateTime (not Date/Instant/ZonedDateTime) for localDateTime variables.","Convert zoned values via LocalDateTime.ofInstant before REST exposure.","Keep converter unit tests covering non-LocalDateTime rejection."],"tags":["localdatetime","rest-variable","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"}