Aktywne Wpisy

PIAN--A_A--KTYWNA +750
źródło: temp_file5306875112373733505
Pobierz
Corvus_Frugilagus +121
Witam wszystkich serdecznie w te sobotnią noc.
źródło: temp_file6554313945994361185
PobierzSkopiuj link
Skopiuj link
źródło: temp_file5306875112373733505
Pobierz
źródło: temp_file6554313945994361185
PobierzRegulamin
Reklama
Kontakt
O nas
FAQ
Osiągnięcia
Ranking
mam ja sobie klasę
@Data@NoArgsConstructorpublic class RegisterDateTimeRequest{@DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss")@JsonFormat(shape = JsonFormat.Shape.STRING)private LocalDateTime dateTime;}i mam sobie controller z metodą
@GetMappingpublic RegisterDeviceDateTimeResponse performDeviceDateTime(RegisterDateTimeRequest registerDeviceDateTimeRequest ){// ...}podczas użycia
http://localhost:8080/register?dateTime=2020-10-10T16%3A51%3A02mam błąd 400 a w konsoli
Field error in object 'registerDeviceDateTimeRequest' on field 'dateTime': rejected value [2020-10-10T16:51:02];
codes [typeMismatch.registerDeviceDateTimeRequest.dateTime,typeMismatch.dateTime,typeMismatch.java.time.LocalDateTime,typeMismatch];
arguments [org.springframework.context.support.DefaultMessageSourceResolvable: codes [registerDeviceDateTimeRequest.dateTime,dateTime];
arguments []; default message [dateTime]];
default message [Failed to convert property value of type 'java.lang.String' to required type 'java.time.LocalDateTime' for property 'dateTime';
nested exception is org.springframework.core.convert.ConversionFailedException: Failed to convert from type [java.lang.String] to type
[@org.springframework.format.annotation.DateTimeFormat @com.fasterxml.jackson.annotation.JsonFormat java.time.LocalDateTime]
for value '2020-10-10T16:51:02';
nested exception is java.lang.IllegalArgumentException: Parse attempt failed for value [2020-10-10T16:51:02]]]
o co kaman?!
Ewentualnie poleciłbym sprawdzić przekazywanie wartości do pola "iso" w tejże adnotacji, masz kilka standardowych formatów, a może któryś okaże się idealny w twojej sytuacji
@Bairei: @imarid: racja wyszło na to, że to musi być iso w adnotacji od DateTimeFormat, przerobienie klasy z adnotacją
@DateTimeFormat(iso = DateTimeFormat.ISO.DATE_TIME)przyjmuje wartość nawet z dokładnością co do minuty. Bardziej jest to wyjaśnione w poście poniżej zaakceptowanego,