The conversion of the property value from type 'java.lang.String' to the required type 'java.time.LocalDate' failed in the JHipster generated file

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)]

Answer №1

If you're encountering issues with the backend not recognizing the JavaScript date string being passed, one simple solution is to utilize JHipster's preferred date/time library like dayjs or momentjs for older versions.

import * as moment from 'moment';
// ...
        'transStartDate.equals': moment()
// ...

Alternatively:

import * as dayjs from 'dayjs';
// ...
        'transStartDate.equals': dayjs()
// ...

This approach should theoretically retrieve all instances of Transaction where the transStartDate matches the current date.

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Ensure that child components' property types are enforced in TypeScript

I am trying to enforce the type of a property in a child component. I expected the code below not to compile because Child's property name is not correctly typed inside Parent within the app. However, there is no compiler warning displayed. Is there ...

Expanding external type declarations within Typescript

I am currently working with Typescript and the ant design library. My goal is to extend an existing interface by adding a single property. To start, I imported the original interface so you can see the folder structure: import { CollapseProps } from &apo ...

Unable to attach 'gridOptions' as it is not a recognized attribute of 'ag-grid-angular' component (Angular4)

I am facing an issue with my HTML code and Angular components: <ag-grid-angular [gridOptions]="gridOptions"></ag-grid-angular> My component code is as follows: import {GridOptions} from 'ag-grid'; ... export class SampleComponent ...

One run is all it takes for a try-catch loop

My code contains a try-catch block that is designed to catch any input that is not an integer. When I input a non-integer value such as 5.6, it correctly notifies me that only integers are allowed and prompts me to try again. However, if I submit another ...

Defining Objects in TypeScript

Within my TypeScript application, I currently have the following code: interface Data { url: string, // more stuff } (...) export class something() { public data: Data; } method(){ this.data.url = "things"; } However, every time I atte ...

Using IONIC2 to localize month names in the UI

I am encountering a challenge with ionic2 related to translating month names into Portuguese for Brazil. In my views, I utilize the date filter to display the full month names, but they are currently appearing in English. I need them to be displayed in Bra ...

Ensure that the status bar remains visible while in full screen mode on Ionic for both android and iOS devices

Greetings! I am currently developing an application with Ionic/Cordova and I have a question regarding enabling the full screen mode while also displaying the status bar. I have already added the following code to my config.xml file: Could someone provide ...

Display text when hovered over or clicked to insert into an HTML table

I have an HTML table connected with a component field gameArray and I need it to: Show 'H' when the user's cursor hovers over TD (:hover) and the corresponding field in gameArray is an empty string, Fill the gameArray field after a click. ...

How can I access a nested FormArray in Angular?

I have a situation where I am trying to access the second FormArray inside another FormArray. Here is an excerpt from my component: registrationForm = new FormGroup({ registrations: new FormArray([this.patchRegistrationValues()]) }); patchRegistrati ...

Integrating support for the Xtext editor with an external ANTLR parser

For my IoTSuite project, I have developed a system that takes high-level specifications, parses them, and generates code in Java and Android. Initially, I used ANTLR grammar for parsing and StringTemplate for code generation. However, in order to enhance ...

What is the best method to select seven random items from a list that was previously converted from an array?

public static String doDraw(String cardName[], int deckSize){ int counter, n; String list; List<Cin> cardList = Arrays.asList(cardName); Collections.shuffle(cardList); ? cardList = cardList.get(7); System.out.println(cardList); ...

Is it possible to divide an Observable<boolean[]> into an array of Observable<boolean>?

Within a component, I have the following code snippet: // this.can... are boolean values redux .watch(state => state.userInfo.access.current) .takeUntil(this.done) .subscribe(access => [this.canPartners, this.canServices, this.canTens, thi ...

Utilize SCSS values within TypeScript by applying them on a class level

let changeClassDisplay = document.getElementsByClassName('sidebar'); for (var i = 0; i < changeClassDisplay.length; i += 1) { changeClassDisplay[i].style.display = 'block'; } I encountered an issue with this code whe ...

How can a child component class in Angular 2 be initialized when extending a parent class?

Let's consider a scenario where we have a component called ChildComponent that extends from the Parent class. How do we go about initializing the ChildComponent class? In Angular 2, when this component is used in HTML, it automatically invokes the Chi ...

Error message: Unable to set the uploaded file in the specified state within a React application

I am currently working on a react application that involves file uploads. My goal is to update the state variable with the uploaded file in either .docx or .pdf format as soon as it is uploaded. However, when I try to set the state, it shows up as undefine ...

"Creating a Typescript array by extracting items from a different const array (as seen in the official beginner tutorial

Currently, I am working through the Angular tutorial that can be found at https://angular.io/start. After successfully completing the tutorial, I decided to practice building for production locally. However, when attempting to build, I encountered this err ...

Please do not attempt to switch to the window until it is fully open

Experiencing an issue with my tests where I encounter no frame exceptions and Out of bounds exception after selecting a button and switching to the window that opens. Here is my code snippet: clickWithActions(driver, launchNote); sleepForTi ...

Having trouble deleting a component from an array in React?

I am facing an issue with my array and component functions. Each component has a handleRemove function that is supposed to remove the selected component from the array. However, the function is not working as expected. Instead of deleting just the selected ...

Spring Data Neo4j will only update an existing node with the same properties and will not insert a new node

Every time I attempt to save a new node for the SpringData with identical properties and relationships to an existing node, it merely updates the existing node and doesn't insert the new one. I'm saving it with a null ID. What could be causing t ...

Implement a default dropdown menu that displays the current month using Angular and TypeScript

I am looking to implement a dropdown that initially displays the current month. Here is the code snippet I have used: <p-dropdown [options]="months" [filter]="false" filterBy="nombre" [showClear] ...