I have an endpoint that accepts @ResponseBody.
But when I sent the data, I could not understand why the status 400 was coming to me in response. There was nothing in the logs that could tell me.
- build.gradle
plugins {
id 'org.springframework.boot' version '2.7.5'
id 'io.spring.dependency-management' version '1.0.15.RELEASE'
id 'java'
}
group = 'com.example'
version = '0.0.1-SNAPSHOT'
sourceCompatibility = '17'
{
...
implementation 'org.springframework.boot:spring-boot-starter-web'
implementation 'org.springframework.boot:spring-boot-starter-data-jpa'
implementation 'com.fasterxml.jackson.core:jackson-annotations'
implementation 'org.flywaydb:flyway-core'
implementation 'org.springframework.cloud:spring-cloud-starter-config'
implementation 'org.springframework.cloud:spring-cloud-starter-netflix-eureka-client'
implementation 'org.springframework.boot:spring-boot-starter-aop'
implementation 'org.springframework.boot:spring-boot-starter-actuator'
implementation 'org.springframework.boot:spring-boot-starter-validation'
....
}
- controller
@PostMapping(value = "new")
public ResponseEntity<TDto> addNew(@Valid @RequestBody TDto dto) {
...
}
- application.yml
logging:
level:
org:
springframework:
web:
filter:
CommonsRequestLoggingFilter: DEBUG
util:
ContentCachingRequestWrapper: DEBUG
ContentCachingResponseWrapper: DEBUG
management:
endpoints:
web:
exposure:
include: httptrace
I have the dto:
@Builder
@NoArgsConstructor
@AllArgsConstructor
@EqualsAndHashCode
@ToString
public class TDto {
private Long id;
.....
@JsonSerialize(using = LocalDateTimeSerializer.class)
@JsonProperty("t_date")
private LocalDateTime tDate;
It turned out that jackson can't convert a date in this format
"2022-10-22 10:17:37.402150 +00:00"
but it works with a date of this format
"2021-08-02T03:00:00"
To make it work, I had to do this:
@JsonProperty("t_date")
@JsonSerialize(using = LocalDateTimeSerializer.class)
private LocalDateTime tDate;
and the date has to be transmitted strictly in this format"
"2021-09-15T10:15:37.93456"
or
"2021-09-17T10:14:37"
and how to set up different formats is not understood.
For example, I can't use time variables in Postman
"t_date": {{$timestamp}},
since in this case, its own date format is generated (also timestamp).
But the worst thing is that I don't see any errors in the logs.
They just don't exist.
In addition, how in general can you configure several Jackson date serializers and specify that Jackson automatically selects the appropriate one, and if it does not find it, then throws the user exception?
This error was not in close visibility, how to enable logging of such problems?