Hi,
Disable validation (eg: context.getParserConfiguration().setValidating(false)) only works for PipeParser, but it does not work for the XMLParser in Hapi 2 v2.3.
Note: the codes below work with Hapi 2 v2.2
String inValidMessage = "MSH|^~\\&|MedSeries|CAISI_1-2|PLS|3910|200903230934||ADT^A31^ADT_A05|75535037-1237815294895|P^T|2.4\r"
+ "EVN|A31|THIS-IS-NOT-DATE-VALUE\r"
+ "PID|1||29^^CAISI_1-2^PI~\"\"||Test300^Leticia^^^^^L||19770202|M||||||||||||||||||||||";
HapiContext context = new DefaultHapiContext();
context.getParserConfiguration().setValidating(false); // disable validation
Message hapiMsg = null;
String xmlDoc = null;
PipeParser parser = context.getPipeParser();
hapiMsg = parser.parse(inValidMessage); // successfull parsed
xmlDoc = xmlParser.encode(hapiMsg,"XML");
XMLParser xmlParser = context.getXMLParser();
Message xmlMessage = xmlParser.parse(xmlDoc);// an exception is thrown here
//Validation failed: Primitive value 'THIS-IS-NOT-DATE-VALUE' requires to be empty or a HL7 datetime string
True. The DefaultXMLParser did not set himself as parser being responsible for the message being created. Fixed with https://github.com/hapifhir/hapi-hl7v2/commit/f17db02ce8bcfd5df25a894039186719c432df3e
Thanks Christian for the fix!