flowable/flowable-engine · error · FlowableException

Could not deserialize event to json

Error message

Could not deserialize event to json

What it means

StringToJsonDeserializer.deserialize converts a raw event (its toString()) into a Jackson JsonNode via objectMapper.readTree. If the raw event string is not valid JSON, Jackson throws JacksonException, which is wrapped in a FlowableException 'Could not deserialize event to json'.

Source

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

/**
 * @author Joram Barrez
 * @author Filip Hrisafov
 */
public class StringToJsonDeserializer implements InboundEventDeserializer<JsonNode> {

    protected final ObjectMapper objectMapper;

    public StringToJsonDeserializer(ObjectMapper objectMapper) {
        this.objectMapper = objectMapper;
    }

    @Override
    public JsonNode deserialize(Object rawEvent) {
        try {
            return objectMapper.readTree(rawEvent.toString());
        } catch (JacksonException e) {
            throw new FlowableException("Could not deserialize event to json", e);
        }
    }
    
}

View on GitHub (pinned to d6d39ce1c6)

Solutions

  1. Log/print rawEvent.toString() and validate it with a JSON parser to find the syntax error.
  2. Ensure the inbound channel/adapter matches the producer's format (JSON producer for StringToJsonDeserializer).
  3. If rawEvent is an object, serialize it with objectMapper.writeValueAsString before deserializing.
  4. Validate producer output for truncation/encoding issues (e.g. charset mismatch in the transport).

Example fix

// before
deserializer.deserialize(someXmlString); // throws

// after
deserializer.deserialize(objectMapper.writeValueAsString(myDto));
Defensive patterns

Strategy: validation

Validate before calling

ObjectMapper probe = new ObjectMapper();
try {
    probe.readTree(rawEvent.toString());
} catch (JacksonException e) {
    throw new IllegalArgumentException("Raw event is not valid JSON: " + e.getOriginalMessage());
}
// safe to call deserializer.deserialize(rawEvent)

Type guard

boolean isValidJson(ObjectMapper mapper, Object rawEvent) {
    try {
        mapper.readTree(rawEvent.toString());
        return true;
    } catch (Exception e) {
        return false;
    }
}

Try / catch

try {
    JsonNode node = deserializer.deserialize(rawEvent);
} catch (FlowableException e) {
    logger.error("Event is not valid JSON: {}", rawEvent);
    // route to dead-letter / error channel
}

Prevention

When it happens

Trigger: deserialize(rawEvent) invoked with a payload that is not valid JSON — e.g. an XML or plain-text body on a JSON event-registry channel, an empty string, truncated JSON, or an object whose toString() is not its JSON representation.

Common situations: Wrong channel adapter configured (XML producer feeding a JSON channel); producers sending invalid or truncated JSON; using a Java object as rawEvent whose toString() is not JSON; malformed encoding/mangled messages from a message broker.

Understand the failure class

Background: JSON parse error: "Unexpected token" / "not valid JSON" / "failed to parse" — what JSON parsers are really complaining about — this error's family across 45 libraries.

Related errors


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