0

I am trying to pass LocalDateTime in the request param of a method but it always logs null. Please help me figure out what I did wrong here:

@Path("/book/workOrderId/{workOrderId}")
@PUT
    public Response bookWorkOrder(@Context HttpHeaders headers, @PathParam("countryCode") String countryCode,
            @PathParam("workOrderId") int workOrderId,
            @QueryParam("reasonId") int reasonId,
            @RequestParam(value = "dateTime") @DateTimeFormat(pattern = "yyyy-MM-dd'T'HH:mm:ss")  LocalDateTime dateTime

    ) throws CDException {
    
        logger.debug("dateTime outside if::" + dateTime);
        return Response.ok(true).build();
}

Output:

22:32:27.659 [http-nio-8300-exec-2] DEBUG c.c.t.i.e.v.impl.WorkorderController - dateTime outside if::null
Michael
  • 41,989
  • 11
  • 82
  • 128
  • 1
    You are using JAX-RS not Spring MVC thus the `@RequestParam` nor the `@DateTimeFormat` will work as those are for Spring MVC not JAX-RS. – M. Deinum Oct 08 '20 at 17:47
  • so how do we pass localDateTime here? @M.Deinum – user2503061 Oct 08 '20 at 17:49
  • Depends on how you submit it? Is it part of the ULR (`@PathParam`) if it is a parameter use `@QueryParam` and if it is part of the form use `@FormParam`. So it depends on how you submit the data. – M. Deinum Oct 08 '20 at 17:50
  • i want to pass it as a `@QueryParam` but how do we pass local datetime expression in it. dateTime=2020-10-08T14:00:00 in endpoint isn't working using `@QueryParam("bookingTime") LocalDateTime bookingTime` @M. Deinum – user2503061 Oct 08 '20 at 18:01
  • No idea. Not sure how JAX-RS is supporting the `javax.time` stuff (hence the change in your title and added tags so that someone who might know can answer it). – M. Deinum Oct 08 '20 at 18:04
  • https://stackoverflow.com/a/39850842/2587435 – Paul Samsotha Oct 08 '20 at 18:48

1 Answers1

0

This worked for me:

@PUT
    public Response bookWorkOrder(@Context HttpHeaders headers, @PathParam("countryCode") String countryCode,
            @PathParam("workOrderId") int workOrderId, @QueryParam("bookingTime") String bookingTime,
            @QueryParam("reasonId") int reasonId) throws CDException {
        LocalDateTime localDateTime = LocalDateTime.parse(bookingTime, DateTimeFormatter.ISO_DATE_TIME);
        logger.debug("bookingTime:: {}", bookingTime);
return Response.ok(true).build();

}