Closed Prasaddiwalkar closed 1 year ago
any updates?
@Prasaddiwalkar seriously?
Will transfer as this belongs under Java 8 modules (which provides support for Java 8 date/time)
@Prasaddiwalkar seriously?
Will transfer as this belongs under Java 8 modules (which provides support for Java 8 date/time)
Yes, I have added code snippet please try to reproduce. Let me know if you face any issue in reproducing it.
One quick note: setDateFormat()
only works for java.util.Date
and java.util.Calendar
, not Java 8 date/time types (or Joda). Latter use @JsonFormat
annotation on property, or via "Config Override" system (shown in unit tests).
Also: @DateTimeFormat
is not an annotation Jackson directly knows about, being Spring annotation. I guess something in Spring might configure ObjectMapper
but Jackson itself is not aware of that annotation.
Examples can be found from:
src/test/java/com/fasterxml/jackson/datatype/jsr310/deser/LocalDateDeserTest.java
so for example:
Value format = JsonFormat.Value
.forPattern("dd-MMM-yy");
mapper.configOverride(LocalDate.class).setFormat(format);
to configure pattern that might work.
The default format accepted seems to be:
DateTimeFormatter.ISO_LOCAL_DATE
I think above configuration should allow handling: will close this issue in a couple of days (unless there's an update indicating further problems).
still same error
@Prasaddiwalkar same error if using configuration override I showed? That should change handling to accept values as represented, unlike original configuration.
I would need a stand-alone reproduction here -- isolated unit test. As things are, I cannot see what exactly is supposed to fail and cannot really do anything about possible problem.
May be re-opened with a reproduction with assertions (like junit test), not just description (or code that does not specify what is expected behavior, with what input etc).
I am getting following exception.
Scenario:- I am getting a date from downstream API in
dd-MMM-yy
format e.g07-OCT-21
my requirement is my API should return date in ISO_DATE format i.e. 'yyyy-MM-dd'. We have swagger specification files using which we are generating a boilerplate code using swaggger-codegen maven plugin target. So it adds@DateTimeFormat(iso = DateTimeFormat.ISO.DATE)
annotation for date.From mapper my expectation is while mapping json to java class it should transform date from
dd-MMM-yy
toyyyy-MM-dd
format as per ISO_DATE format.code to reproduce
Sample response coming from downstream application with date
dd-MMM-yy
formatsrc/main/resources/event1.json
Event.java
JacksonDateFormter.java
pom.xml