I have created the files through JHipster and currently facing an issue when trying to execute a query involving a Date variable. The conversion is failing.
Below is my typescript file method that sets the criteria for the search:
loadSearchPage(page?: number): void {
const pageToLoad: number = page || this.page;
this.transactionService
.query({
page: pageToLoad - 1,
size: this.itemsPerPage,
sort: this.sort(),
'transStartDate.equals': new Date()
})
.subscribe(
(res: HttpResponse<ITransaction[]>) => this.onSuccess(res.body, res.headers, pageToLoad),
() => this.onError()
);
}
The method then calls the query within the transaction:
query(req?: any): Observable<EntityArrayResponseType> {
const options = createRequestOption(req);
return this.http
.get<ITransaction[]>(this.resourceUrl, { params: options, observe: 'response' })
.pipe(map((res: EntityArrayResponseType) => this.convertDateArrayFromServer(res)));
}
Here is the default JHipster convertDateArrayFromServer method provided:
protected convertDateArrayFromServer(res: EntityArrayResponseType): EntityArrayResponseType {
if (res.body) {
res.body.forEach((transaction: ITransaction) => {
transaction.transStartDate = transaction.transStartDate ? moment(transaction.transStartDate) : undefined;
transaction.transEndDate = transaction.transEndDate ? moment(transaction.transEndDate) : undefined;
});
}
return res;
}
I have researched methods to address this issue and also tried the following steps. However, the structure of the request level file generated by JHipster was quite different and difficult to modify based on this webpage:
I am seeking assistance for a viable solution to resolve the error message below:
"Failed to convert property value of type 'java.lang.String' to required type 'java.time.LocalDate' for property 'transStartDate.equals'; nested exception is org.springframework.core.convert.ConversionFailedException: Failed to convert from type [java.lang.String] to type [java.time.LocalDate] for value 'Fri Dec 03 2021 09:22:35 GMT 0800 (Singapore Standard Time)'; nested exception is java.lang.IllegalArgumentException: Parse attempt failed for value [Fri Dec 03 2021 09:22:35 GMT 0800 (Singapore Standard Time)]