flowable/flowable-engine · error · FlowableIllegalArgumentException

Cannot convert event payload ${jsonValue} to type 'json'

Error message

Cannot convert event payload ${jsonValue} to type 'json'

What it means

FlowableIllegalArgumentException thrown by EventPayloadToJsonStringSerializer.serialize when a payload declared as type 'json' is neither a JsonNode, Supplier producing one, nor a String — i.e. an arbitrary object the serializer cannot represent as JSON in this branch.

Source

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

                        }
                    } else {
                        JsonNode jsonNode = JsonUtil.asJsonNode(jsonValue, objectMapper, true);
                        if (jsonNode != null) {
                            jsonValue = jsonNode;
                        }
                    }
                    if (jsonValue instanceof JsonNode) {
                        objectNode.set(payloadInstance.getDefinitionName(), (JsonNode) jsonValue);
                    } else if (jsonValue instanceof String) {
                        JsonNode jsonNode;
                        try {
                            jsonNode = objectMapper.readTree((String) jsonValue);
                        } catch (JacksonException e) {
                            throw new FlowableIllegalArgumentException("Could not read json event payload", e);
                        }
                        objectNode.set(payloadInstance.getDefinitionName(), jsonNode);
                    }  else {
                        throw new FlowableIllegalArgumentException("Cannot convert event payload " + jsonValue + " to type 'json'");
                    }

                } else {
                    throw new FlowableIllegalArgumentException("Unsupported event payload instance type: " + definitionType);
                }

            } else {
                objectNode.putNull(payloadInstance.getDefinitionName());
            }
        }

        try {
            return objectMapper.writeValueAsString(objectNode);
        } catch (JacksonException e) {
            throw new FlowableException("Could not serialize event to json string for " + eventInstance, e);
        }
    }

View on GitHub (pinned to d6d39ce1c6)

Solutions

  1. Convert the object to JSON first: objectMapper.valueToTree(obj) and set the resulting JsonNode.
  2. Wrap the value in a Supplier<JsonNode> if lazy resolution is needed.
  3. Change the payload definition type to match the actual value shape, or serialize the object to a JSON String yourself.

Example fix

// before
payload.put("data", myPojo); // POJO under 'json' payload
// after
payload.put("data", objectMapper.valueToTree(myPojo)); // JsonNode
Defensive patterns

Strategy: type-guard

Validate before calling

Object v = payloadValue; if (!(v instanceof JsonNode) && !(v instanceof Supplier) && !(v instanceof String)) { throw new IllegalArgumentException("'json' payload must be JsonNode, Supplier, or String"); }

Type guard

boolean isJsonCompatible(Object v) { return v instanceof JsonNode || v instanceof Supplier<?> || v instanceof String; }

Try / catch

try { serializer.serialize(eventInstance); } catch (FlowableIllegalArgumentException e) { LOG.error("unsupported json payload value: " + e.getMessage()); throw e; }

Prevention

When it happens

Trigger: Payload definition type is 'json' but the instance value is a raw POJO, Map, Number, or other non-JsonNode/non-String/non-Supplier object.

Common situations: Developers putting POJOs or Maps under a 'json'-typed payload expecting automatic conversion; mixing typed payload definitions with untyped values after a schema change.

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/5fd540771524d00b. Report an issue: GitHub.