{"record":{"id":"4a16032b2d83ba4a","repo":"flowable/flowable-engine","slug":"could-not-deserialize-event-to-xml","errorCode":null,"errorMessage":"Could not deserialize event to xml","messagePattern":"Could not deserialize event to xml","errorType":"exception","errorClass":"FlowableException","httpStatus":null,"severity":"error","filePath":"modules/flowable-event-registry/src/main/java/org/flowable/eventregistry/impl/serialization/StringToXmlDocumentDeserializer.java","lineNumber":52,"sourceCode":"            DocumentBuilderFactory documentBuilderFactory = DocumentBuilderFactory.newInstance();\n            \n            documentBuilderFactory.setValidating(false);\n            documentBuilderFactory.setExpandEntityReferences(false);\n            documentBuilderFactory.setXIncludeAware(false);\n            documentBuilderFactory.setFeature(\"http://apache.org/xml/features/nonvalidating/load-external-dtd\", false);\n            documentBuilderFactory.setFeature(\"http://apache.org/xml/features/nonvalidating/load-dtd-grammar\", false);\n            documentBuilderFactory.setFeature(\"http://xml.org/sax/features/external-general-entities\", false);\n            documentBuilderFactory.setFeature(\"http://xml.org/sax/features/external-parameter-entities\", false);\n            \n            \n            DocumentBuilder documentBuilder = documentBuilderFactory.newDocumentBuilder();\n            try (InputStream inputStream = new ByteArrayInputStream(convertEventToBytes(rawEvent))) {\n                Document document = documentBuilder.parse(inputStream);\n                return document;\n            }\n            \n        } catch (Exception e) {\n            throw new FlowableException(\"Could not deserialize event to xml\", e);\n        }\n    }\n\n    public byte[] convertEventToBytes(Object rawEvent) {\n        return rawEvent.toString().getBytes(StandardCharsets.UTF_8);\n    }\n    \n}\n","sourceCodeStart":34,"sourceCodeEnd":61,"githubUrl":"https://github.com/flowable/flowable-engine/blob/d6d39ce1c69ff244f2d9dc6af756a9b95e865586/modules/flowable-event-registry/src/main/java/org/flowable/eventregistry/impl/serialization/StringToXmlDocumentDeserializer.java#L34-L61","documentation":"StringToXmlDocumentDeserializer.deserialize converts the raw event to UTF-8 bytes and parses them with a DocumentBuilder into an org.w3c.dom.Document. Any parse failure (SAXException, IOException, malformed XML) is wrapped in FlowableException 'Could not deserialize event to xml'.","triggerScenarios":"deserialize(rawEvent) invoked with content that is not well-formed XML — e.g. a JSON body on an XML channel, an empty or truncated document, undeclared entity references, or an object whose toString() is not XML.","commonSituations":"JSON producer feeding an XML-configured channel; messages truncated by transport limits; XML with undeclared namespaces/entities or BOM/encoding mismatches; using non-string objects as raw events.","solutions":["Log rawEvent (convertEventToBytes output as UTF-8) and validate it with an XML parser to locate the syntax error.","Ensure the inbound channel deserializer matches the producer's format (XML producer for StringToXmlDocumentDeserializer).","Check for truncation/encoding issues (UTF-8 expected, watch for BOMs and misdeclared encodings).","If rawEvent is not already XML, serialize it properly to an XML string before passing it in."],"exampleFix":"// before\ndeserializer.deserialize(jsonBody); // throws\n\n// after\ndeserializer.deserialize(\"<order><id>1</id></order>\");","handlingStrategy":"validation","validationCode":"DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();\ndbf.setNamespaceAware(true);\ntry {\n    dbf.newDocumentBuilder().parse(new InputSource(new StringReader(rawEvent.toString())));\n} catch (Exception e) {\n    throw new IllegalArgumentException(\"Raw event is not well-formed XML: \" + e.getMessage());\n}\n// safe to call deserializer.deserialize(rawEvent)","typeGuard":"boolean isValidXml(Object rawEvent) {\n    try {\n        DocumentBuilderFactory.newInstance().newDocumentBuilder()\n            .parse(new InputSource(new StringReader(rawEvent.toString())));\n        return true;\n    } catch (Exception e) {\n        return false;\n    }\n}","tryCatchPattern":"try {\n    Document doc = deserializer.deserialize(rawEvent);\n} catch (FlowableException e) {\n    logger.error(\"Event is not well-formed XML: {}\", rawEvent);\n    // route to dead-letter / error channel\n}","preventionTips":["Use XML producers with XML-configured channels; JSON bodies will fail parsing.","Check for truncation, BOMs, and encoding mismatches (UTF-8 expected).","Ensure XML entity/namespace declarations are complete in producer output.","Log raw payloads before parsing for post-mortem debugging."],"tags":["flowable","event-registry","xml","deserialization","sax"],"backgroundTag":"xml-parse-failed","analyzedSha":"d6d39ce1c69ff244f2d9dc6af756a9b95e865586","analyzedAt":"2026-09-11T06:41:19.413Z","contentChangedAt":"2026-09-11T06:41:19.413Z","schemaVersion":2},"datasetVersion":"2026-09-18T11:17:12.947Z"}