Join GitHub today
GitHub is home to over 28 million developers working together to host and review code, manage projects, and build software together.Sign up
Getting DateFormatException when using HAPI FHIR 1.6 or 2.0 or latest snapshot #444
The following code will generate a DiagnosticReport XML string and then attempts to convert that back into the FHIR object.
LocalDateTime ldt = LocalDateTime.of(1960, 9, 7, 0, 44, 25, 12387401); DiagnosticReport dr = new DiagnosticReport(); // HAPI FHIR 1.4 and 1.5 generate a valid timestamp, but 1.6 and 2.0 generated an invalid timestamp dr.setIssued(Date.from(ldt.toInstant(ZoneOffset.UTC))); FhirContext fctx = FhirContext.forDstu3(); IParser xmlParser = fctx.newXmlParser().setPrettyPrint(true); String xml = xmlParser.encodeResourceToString(dr); System.out.println(xml); IBaseResource ibr = xmlParser.parseResource(xml);
Using HAPI FHIR 1.6 or 2.0 or the latest snapshot available, I'm getting a DateFormatException when deserializing the XML string to the FHIR object.
The issue does not exist in HAPI FHIR 1.4 or 1.5.
I attached a Maven project to reproduce the issue.
The serialized date is definitely not correct in that block (not the
Is that what's being produced by
On Fri, Sep 9, 2016 at 5:01 PM, CarthageKing email@example.com
Date.from... is a standard Java library call so I don't think it's a bug in the Java library itself.
I noticed that the internals of the BaseDateTimeType have been updated from 1.4/1.5 to 1.6/newer. I traced the execution and I'm getting the -988 value in this line in BaseDateTimeType.setValue(Date theValue, TemporalPrecisionEnum thePrecision):
The value returned by theValue.getTime() is a negative number and this leads to the negative milliseconds value being used by the BaseDateTimeType.