flowable/flowable-engine · error · FlowableIllegalArgumentException

Cannot convert event payload ${payloadInstanceValue} to type

Error message

Cannot convert event payload ${payloadInstanceValue} to type 'long'

What it means

FlowableIllegalArgumentException thrown by EventPayloadToJsonStringSerializer.serialize when a payload instance declared as type 'long' is neither a Number nor a String, so it cannot be converted to a JSON long during serialization.

Source

Thrown at modules/flowable-event-registry/src/main/java/org/flowable/eventregistry/impl/serialization/EventPayloadToJsonStringSerializer.java:91

                } else if (EventPayloadTypes.INTEGER.equals(definitionType)) {

                    if (payloadInstanceValue instanceof Number) {
                        objectNode.put(payloadInstance.getDefinitionName(), ((Number) payloadInstanceValue).intValue());
                    } else if (payloadInstanceValue instanceof String) {
                        objectNode.put(payloadInstance.getDefinitionName(), Integer.valueOf((String) payloadInstanceValue));
                    } else {
                        throw new FlowableIllegalArgumentException("Cannot convert event payload " + payloadInstanceValue + " to type 'integer'");
                    }

                } else if (EventPayloadTypes.LONG.equals(definitionType)) {

                    if (payloadInstanceValue instanceof Number) {
                        objectNode.put(payloadInstance.getDefinitionName(), ((Number) payloadInstanceValue).longValue());
                    } else if (payloadInstanceValue instanceof String) {
                        objectNode.put(payloadInstance.getDefinitionName(), Long.valueOf((String) payloadInstanceValue));
                    } else {
                        throw new FlowableIllegalArgumentException("Cannot convert event payload " + payloadInstanceValue + " to type 'long'");
                    }

                } else if (EventPayloadTypes.BOOLEAN.equals(definitionType)) {

                    if (payloadInstanceValue instanceof Boolean) {
                        objectNode.put(payloadInstance.getDefinitionName(), (Boolean) payloadInstanceValue);
                    } else if (payloadInstanceValue instanceof String) {
                        objectNode.put(payloadInstance.getDefinitionName(), Boolean.valueOf((String) payloadInstanceValue));
                    }  else {
                        throw new FlowableIllegalArgumentException("Cannot convert event payload " + payloadInstanceValue + " to type 'boolean'");
                    }

                } else if (EventPayloadTypes.JSON.equals(definitionType)) {
                    Object jsonValue = payloadInstanceValue;
                    if (payloadInstanceValue instanceof Supplier<?>) {
                        Object suppliedValue = ((Supplier<?>) payloadInstanceValue).get();
                        JsonNode jsonNode = JsonUtil.asJsonNode(suppliedValue, objectMapper, true);
                        if (jsonNode != null) {

View on GitHub (pinned to d6d39ce1c6)

Solutions

  1. Set the payload value as a Long/Number (or numeric String) matching the 'long' definition.
  2. Adjust the payload definition type if the value is not numeric.
  3. Validate types when building the EventInstance payload.

Example fix

// before
payload.put("timestamp", instantObject);
// after
payload.put("timestamp", instantObject.toEpochMilli());
Defensive patterns

Strategy: type-guard

Validate before calling

Object v = payloadValue; if (!(v instanceof Number) && !(v instanceof String)) { throw new IllegalArgumentException("payload 'long' value must be Number or numeric String"); }

Type guard

boolean isLongCompatible(Object v) { return v instanceof Number || v instanceof String; }

Try / catch

try { serializer.serialize(eventInstance); } catch (FlowableIllegalArgumentException e) { LOG.error("payload type mismatch for long field: " + e.getMessage()); throw e; }

Prevention

When it happens

Trigger: Payload definition declares type 'long' but the instance value is an incompatible object type at serialize time.

Common situations: Timestamps/IDs passed as non-numeric objects; producers using String-typed big identifiers wrapped in POJOs; payload maps built dynamically with wrong types.

Understand the failure class

Background: Type mismatch errors: IllegalArgumentException, TypeError and type guards across 150 open-source libraries — this error's family across 150 libraries.

Related errors


AI-assisted analysis of flowable/flowable-engine@d6d39ce1c6 (2026-09-11). Data as JSON: /api/errors/9df17ffcd1f0a958. Report an issue: GitHub.