{"record":{"id":"fcba08d229c59ca2","repo":"flowable/flowable-engine","slug":"could-not-deserialize-event-to-json","errorCode":null,"errorMessage":"Could not deserialize event to json","messagePattern":"Could not deserialize event to json","errorType":"exception","errorClass":"FlowableException","httpStatus":null,"severity":"error","filePath":"modules/flowable-event-registry/src/main/java/org/flowable/eventregistry/impl/serialization/StringToJsonDeserializer.java","lineNumber":39,"sourceCode":"\n/**\n * @author Joram Barrez\n * @author Filip Hrisafov\n */\npublic class StringToJsonDeserializer implements InboundEventDeserializer<JsonNode> {\n\n    protected final ObjectMapper objectMapper;\n\n    public StringToJsonDeserializer(ObjectMapper objectMapper) {\n        this.objectMapper = objectMapper;\n    }\n\n    @Override\n    public JsonNode deserialize(Object rawEvent) {\n        try {\n            return objectMapper.readTree(rawEvent.toString());\n        } catch (JacksonException e) {\n            throw new FlowableException(\"Could not deserialize event to json\", e);\n        }\n    }\n    \n}\n","sourceCodeStart":21,"sourceCodeEnd":44,"githubUrl":"https://github.com/flowable/flowable-engine/blob/d6d39ce1c69ff244f2d9dc6af756a9b95e865586/modules/flowable-event-registry/src/main/java/org/flowable/eventregistry/impl/serialization/StringToJsonDeserializer.java#L21-L44","documentation":"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'.","triggerScenarios":"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.","commonSituations":"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.","solutions":["Log/print rawEvent.toString() and validate it with a JSON parser to find the syntax error.","Ensure the inbound channel/adapter matches the producer's format (JSON producer for StringToJsonDeserializer).","If rawEvent is an object, serialize it with objectMapper.writeValueAsString before deserializing.","Validate producer output for truncation/encoding issues (e.g. charset mismatch in the transport)."],"exampleFix":"// before\ndeserializer.deserialize(someXmlString); // throws\n\n// after\ndeserializer.deserialize(objectMapper.writeValueAsString(myDto));","handlingStrategy":"validation","validationCode":"ObjectMapper probe = new ObjectMapper();\ntry {\n    probe.readTree(rawEvent.toString());\n} catch (JacksonException e) {\n    throw new IllegalArgumentException(\"Raw event is not valid JSON: \" + e.getOriginalMessage());\n}\n// safe to call deserializer.deserialize(rawEvent)","typeGuard":"boolean isValidJson(ObjectMapper mapper, Object rawEvent) {\n    try {\n        mapper.readTree(rawEvent.toString());\n        return true;\n    } catch (Exception e) {\n        return false;\n    }\n}","tryCatchPattern":"try {\n    JsonNode node = deserializer.deserialize(rawEvent);\n} catch (FlowableException e) {\n    logger.error(\"Event is not valid JSON: {}\", rawEvent);\n    // route to dead-letter / error channel\n}","preventionTips":["Match the channel deserializer to the producer format (JSON channel for JSON producers).","Log the raw payload before parsing so failures are diagnosable.","Never rely on Java object toString() as JSON — serialize explicitly with ObjectMapper.","Validate/truncate-check messages at the transport boundary (broker, HTTP body)."],"tags":["flowable","event-registry","json","jackson","deserialization"],"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-14T05:17:10.506Z"}