I am getting an Assertion error " Body Content Expected child but was null when asserting the andExpect XML. If I input as as a String "2020-10-01-5:00" it works fine but if I concatenate the date into a string like:
LocalDate startDate = LocalDate.now().minusDays(90);
String startDateLine = "<start-date>" + startDate + "-5:00</start-date>\n";
It throws the AssertionError. I have verified that the XML is correct before the call so I am unsure what about getting the date and converting to a string causes the test to fail.
Update
Do not add the offset string to the
LocalDatestring in order to convert it into anOffsetDateTimestring. Shown below is the idiomatic way to convert aLocalDatetoOffsetDateTimeDemo:
Output:
ONLINE DEMO
You can get the
Stringrepresentation of anOffsetDateTimeusing the functionOffsetDateTime#toStringe.g.Original answer
HH:mme.g.-05:00so that it conforms to ISO 8601 standards.DateTimeFormatterBuilderwith.parseDefaulting(ChronoField.HOUR_OF_DAY, 0)to default the hour-of-day to 0.OffsetDateTimeas it has timezone offset andOffsetDateTimeis the best fit to represent Date-Time with timezone offset.Demo:
Output:
ONLINE DEMO
Notice the optional pattern inside a square bracket.
Learn more about the modern Date-Time API* from Trail: Date Time.