Hapi xml parser is giving following exception while encoding the HL7 v2.7 message using Hapi Xml Parser.
ca.uhn.hl7v2.HL7Exception: Can't XML-encode a GenericMessage. Message must have a recognized structure.
Below is my code snippet that i am using to encode message
HapiContext context = new DefaultHapiContext(modelClassFactory)
PipeParser pipeParser = context.getPipeParser();
pipeParser.setValidationContext(new NoValidation());
pipeParser.getParserConfiguration().setAllowUnknownVersions(true);
Message msg = pipeParser.parse(document);
Parser xmlParser = context.getXMLParser();
return xmlParser.encode(msg);
Any suggestion/solutions?