Issue
I have an endpoint
@GetMapping
fun search(
filter: GuaranteeApplicationFilter,
@SortDefaults(
SortDefault(sort = ["docNumber"], direction = Sort.Direction.DESC),
SortDefault(sort = ["createTime"], direction = Sort.Direction.DESC),
SortDefault(sort = ["id"], direction = Sort.Direction.DESC)
) page: PaginationParametersDto,
@ApiParam(hidden = true) @AuthenticationPrincipal userId: String
): JsonItem<SliceDto<GuaranteeApplicationSearchDto>>
and a class
@JsonIgnoreProperties(ignoreUnknown = true)
data class GuaranteeApplicationFilter(
@DateTimeFormat(iso = DateTimeFormat.ISO.DATE)
var docDateFrom: LocalDate?,
@DateTimeFormat(iso = DateTimeFormat.ISO.DATE)
var docDateTo: LocalDate?,
var docNumber: String?,
var inn: String?,
var shortName: String?,
var amountFrom: BigDecimal?,
var amountTo: BigDecimal?,
var currency: String?,
var type: String?,
var status: String?,
var liability: String?
) : DocumentFilter()
so when I pass a date string like 2022-08-02 I get "Failed to convert property value of type 'java.lang.String' to required type 'java.time.LocalDate'" error.
In debug mode conversion is successful [https://i.stack.imgur.com/jSSDJ.png] but then I get exception.
If I use spring.mvc.format.date=yyyy-MM-dd without @DateTimeFormat all works fine.
Solution
Finally, I've found the answer. It was quite easy. I just need to change:
@DateTimeFormat(iso = DateTimeFormat.ISO.DATE)
to
@field:DateTimeFormat(iso = DateTimeFormat.ISO.DATE)
Answered By - 3mendous
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.