How to convert Date type Angular to LocalDate in Java

Discussão em 'Angular' iniciado por Cédric R, Dezembro 20, 2024.

  1. Cédric R

    Cédric R Guest

    I have a frontend part in Angular 7 and a backend part in Java with Spring Boot framework. I want to post to my backend a Date object. In backend I have a Local Date object. I don't need LocalDateTime object

    my date service in angular. I need to preserve Date type and not use string.

    addDate(): Observable<Date> {
    let now = new Date();
    return this.http
    .post<Date>('/api/date', now)
    .pipe(
    tap(response => {
    return response;
    }),
    catchError(error => this.notificationService.handleError(error))
    );
    }


    my backend service :

    @PostMapping
    public LocalDate addIrregularity(@RequestBody LocalDate date, HttpServletRequest request) {
    log.info(date);
    return date;
    }


    And i have this error:


    2019-08-06 08:21:02.185 WARN 1444 --- [nio-8080-exec-4] .w.s.m.s.DefaultHandlerExceptionResolver : Resolved [org.springframework.http.converter.HttpMessageNotReadableException: JSON parse error: Cannot deserialize value of type java.time.LocalDate from String "2019-08-06T00:00:00.000+0000": Failed to deserialize java.time.LocalDate: (java.time.format.DateTimeParseException) Text '2019-08-06T00:00:00.000+0000' could not be parsed, unparsed text found at index 23; nested exception is com.fasterxml.jackson.databind.exc.InvalidFormatException: Cannot deserialize value of type java.time.LocalDate from String "2019-08-06T00:00:00.000+0000": Failed to deserialize java.time.LocalDate: (java.time.format.DateTimeParseException) Text '2019-08-06T00:00:00.000+0000' could not be parsed, unparsed text found at index 23
    ​

    Continue reading...

Compartilhe esta Página