The API for parseLocalDate says it will throw UnsupportedOperationException
"if parsing is not supported". What does it mean by 'if parsing is not supported'? I'm looking through the source and can not find anywhere that throws UnsupportedOperationException
. Has anyone ever been in a scenario where this exception was thrown from calling parseLocalDate
?
DateTimeFormatter have two usages:
- print dates;
- parse dates;
When you create DateTimeFormatter instance, you pass to it DateTimePrinter and DateTimeParser.
If your formatter has only printer, and you want parse date - UnsupportedOperationException
will be thrown.
If your formatter has only parser, and you want print date - UnsupportedOperationException
will be thrown.
Example
DateTimeFormatter formatter = new DateTimeFormatter(new DateTimePrinter()
{
// implements all abstract methods
}, null); // this instance has printer and hasn't parser
formatter.print(new DateTime()); // works well
formatter.parseDateTime("datetimestring"); // throws exeption
ISODateTimeFormat.dateTime()
and ISODateTimeFormat.dateTimeParser()
. If you used the latter and try for .format(dateTime)
, you get this exception. –
Downall Wanted to asnwer this just because I want to call out @membersound comment to @Ilya answer as it was what was wrong with my code. Basically my team inherited some legacy code and who ever wrote the serializer for Joda DateTime set the formatter using ISODateTimeFormat.dateTimeParser()
instead of ISODateTimeFormat.dateTime()
.
It especially confused me because the only error I saw at first was not an UnsupportedOperationException
, but was instead logged as com.fasterxml.jackson.databind.JsonMappingException: Printing not supported
, which I had a hard time finding when Googling it (as it was likely a recapturing of the actual error). I hope that helps someone else who spent maybe a little too long trying to figure out what was wrong like I did.
© 2022 - 2025 — McMap. All rights reserved.
org.joda.time.format.DateTimeFormat.forPattern(String)
will always return aDateTimeFormatter
with both a printer and a parser; so aDateTimeFormatter
retrieved viaforPattern
should not ever throwUnsupportedOperationException
correct? – Beverly