I am trying to query my database by passing a date param as path variable on postman using a get mapping, however i keep getting this error "I am trying to query my database by passing a date param as path variable on postman using a get mapping, however I keep getting this error
org.springframework.web.method.annotation.MethodArgumentTypeMismatchException: Failed to convert value of type 'java.lang.String' to required type 'java.sql.Date'; nested exception is org.springframework.core.convert.ConversionFailedException: Failed to convert from type [java.lang.String] to type [@org.springframework.web.bind.annotation.PathVariable @org.springframework.format.annotation.DateTimeFormat java.sql.Date] for value '2019-07-24 11:50:34.896+01'; nested exception is org.springframework.core.convert.ConverterNotFoundException: No converter found capable of converting from type [java.util.Date] to type [@org.springframework.web.bind.annotation.PathVariable @org.springframework.format.annotation.DateTimeFormat java.sql.Date]]
I have tried using the @DateTimeFormat
as suggested by various people on line but it still isn't working.
@GetMapping("/walletledger/{fromDate}/{toDate}/{currencycode}")
@PreAuthorize("hasAuthority('SUPERADMIN')")
public List < LedgerResponseDTO > fetchWalletLedgers(
@PathVariable("fromDate") @DateTimeFormat(iso = DateTimeFormat.ISO.DATE) Date fromDate,
@PathVariable("toDate") @DateTimeFormat(iso = DateTimeFormat.ISO.DATE) Date toDate
}
Implementation
@Override
public List < LedgerResponseDTO > fetchWalletLedgers(
Date fromDate,
Date toDate,
CurrencyCode currencyCode,
Pageable pageable) {
List < LedgerResponseDTO > ledgerList = new ArrayList < > ();
ledgerRepository.findByExecutionDateAndExecutionDateAndCurrencyCode(fromDate, toDate, currencyCode).forEach(ledger - > {