1

If I use LocalDate type in my entity class I get the following error if I send a POST request:

com.fasterxml.jackson.databind.exc.InvalidDefinitionException: Cannot construct instance of `java.time.LocalDate` (no Creators, like default construct, exist): no String-argument constructor/factory method to deserialize from String value ('1977-01-01')
 at [Source: (io.undertow.servlet.spec.ServletInputStreamImpl); line: 1, column: 533]

If I change my attribute type from

@JsonbDateFormat("yyyy-MM-dd")
private java.time.LocalDate mydate;

to

@JsonbDateFormat("yyyy-MM-dd")
private java.util.Date mydate;

it works!

I have tested with Wildfly 15 and 16 (Eclipse Yasson implementation) and the new Java date classes doesn't seem to work with JSON-Bindings.

Is this not supported or do I something wrong?

surfspider
  • 727
  • 3
  • 11
  • 25
  • How are you attempting to parse the object? The exception is from Jackson, but you mention Yasson. I used the `JsonbBuilder` and it worked for me. – James R. Perkins May 24 '19 at 23:54
  • I annotated my method like this: `@POST @Consumes(MediaType.APPLICATION_JSON) public Response add(@Valid Customer newCustomer, @Context UriInfo uriInfo) { ... }`. Shouldn' it automatically be parsed by the framework of the wildfly server? It works like this with java.util.Date. – surfspider May 27 '19 at 10:32
  • One thing to note is Yasson is not being used here, Jackson is. I changed my test to use similar parameters and it seemed to work for me. Do you by chance have some kind of reproducer? – James R. Perkins May 28 '19 at 20:46
  • My Customer entity was annotated with javax.xml.bind.annoation.XmlRootElement. If I remove this annotation from the Customer entity it works :-) – surfspider Jun 03 '19 at 08:57

1 Answers1

0

In my case I Added this annotation to java.util.Date fields and this works;

@JsonFormat(pattern = "yyyy-MM-dd'T'HH:mm:ss.SSSXXX")
private Date myDateField;

The pattern values should take all time units;

duvanjamid
  • 557
  • 5
  • 9