Error occurred after attempting to make a GET request

What I aim to achieve:

I need to send two parameters from the front-end to the back-end.

This is the code snippet:

In TypeScript file:

activeFromActiveToQuery(req?: any): Observable<ResponseWrapper>{
        const options = createRequestOption(req);
        options.params.append("active_from", req.active_from.toString());
        options.params.append("active_To", req.active_to.toString());

        return this.http.get(this.resourceActiveFromActiveToURL, options)
            .map((res: Response) => this.convertResponse(res));
    }

checkOverlappingDates (recommendedSection: RecommendedSection) {
        this.activeFromActiveToQuery({
            active_from: recommendedSection.activeFrom,
            active_to: recommendedSection.activeTo
        }).subscribe((data) => {
            var retValue;
            if(data.json == ""){
                retValue = false;
            }else{
                retValue = true;
            }
            return retValue;

In Java Resource class:

public ResponseEntity<List<RecommendedSection>> getRecommendedSectionActiveFromAndActiveToMatching(@RequestParam("active_from") @DateTimeFormat(iso = DateTimeFormat.ISO.DATE_TIME) DateTime active_from, 
                                                                                                       @RequestParam("active_to") @DateTimeFormat(iso = DateTimeFormat.ISO.DATE_TIME) DateTime active_to){
        log.debug("REST request to get active_from and active_to: {}", active_from, active_to);
        List<RecommendedSection> entityList = recommendedSectionService.findRecommendedSectionActiveFromAndActiveToMatching(active_from, active_to);
        return ResponseEntity.ok().body(entityList);
    }

The Issue at hand:

An error message stating the following Bad Request is received:

"Failed to convert value of type 'java.lang.String' to required type 'org.joda.time.DateTime'; nested exception is org.springframework.core.convert.ConversionFailedException: Failed to convert from type [java.lang.String] to type [@javax.validation.Valid @org.springframework.web.bind.annotation.RequestParam @org.springframework.format.annotation.DateTimeFormat org.joda.time.DateTime] for value '[object Object]'; nested exception is java.lang.IllegalArgumentException: Invalid format: "[object Object]""

Apologies if the solution appears straightforward. I have struggled to find a fix that works for me.

Any suggestions on how to resolve this issue?

Answer №1

When working with ISO datetime format, ensure that your request parameters (active_from and active_to) are in the following format: yyyy-MM-dd'T'HH:mm:ss.SSSXXX. For example, 2020-10-12T00:01:01 is a suitable value. It is also recommended to use LocalDateTime instead of Joda dateTime.

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

Arrange information in table format using Angular Material

I have successfully set up a component in Angular and Material. The data I need is accessible through the BitBucket status API: However, I am facing an issue with enabling column sorting for all 3 columns using default settings. Any help or guidance on th ...

"Embarking on a journey with Jackson and the power

There have been numerous questions regarding the use of Jackson for serializing/deserializing Java objects using the builder pattern. Despite this, I am unable to understand why the following code is not functioning correctly. The Jackson version being use ...

The deserialization of 0 and 1 to "Boolean?" failed in Moshi

When attempting to deserialize a JSON field with values of 0, 1, or null into a "Boolean?" data type, the following custom Annotation is used: @Retention(AnnotationRetention.RUNTIME) @JsonQualifier annotation class BooleanType class BooleanAdapter { @ ...

What is the best way to implement bypassSecurityTrustResourceUrl for all elements within an array?

My challenge is dealing with an array of Google Map Embed API URLs. As I iterate over each item, I need to bind them to the source of an iFrame. I have a solution in mind: constructor(private sanitizer: DomSanitizationService) { this.url = sanitizer. ...

Encountering the "Class path not found" error when running Selenium tests with TestNG

My current code snippet is as follows: import java.util.concurrent.TimeUnit; import org.openqa.selenium.By; import org.openqa.selenium.WebDriver; import org.openqa.selenium.firefox.FirefoxDriver; import org.testng.annotations.Test; import org.testng.annot ...

How can I retrieve the source code of a specific section of a webpage using Selenium WebDriver?

Currently, I'm attempting to extract the page source of a particular section on the webpage. When using driver.getPageSource(), the entire source code of the page is returned. My question is - Is there a method to retrieve the HTML content located be ...

Verifying the status of a checkbox label in Java using Selenium

I am currently working on an automation project using Selenium and I'm struggling to figure out how to check the status of a checkbox input. Has anyone else encountered this issue before? Here is a sample code snippet in JavaScript with jQuery: $("i ...

Encountering a Typescript error while attempting to remove an event that has a FormEvent type

Struggling to remove an event listener in Typescript due to a mismatch between the expected type EventListenerOrEventListenerObject and the actual type of FormEvent: private saveHighScore (event: React.FormEvent<HTMLInputElement>) { This is how I t ...

Converting a file into a string using Angular and TypeScript (byte by byte)

I am looking to upload a file and send it as type $byte to the endpoint using the POST method My approach involves converting the file to base64, and then from there to byte. I couldn't find a direct way to convert it to byte, so my reasoning may be ...

Navigating to Angular component from Mapbox popup

I'm currently working on a mobile app with Ionic and Angular. The app features various Mapbox markers that open custom popups when clicked, each displaying unique content. I want the button within the popup to redirect users to a page with more inform ...

storing the input values in a cache

When a user enters a query into the search form and submits it, they are taken to a results page displaying the search results. If the user then clicks on the browser's back button, I want them to be directed back to the search form with their previou ...

Modify the title and go back dynamically in the document

I am currently working on a timer app where I want to dynamically change the document title. The app features a countdown timer, and during the countdown, I was able to display the timer in the document title successfully. However, once the countdown is co ...

Struggling to update TypeScript and encountering the error message "Unable to establish the authenticity of host 'github.com (192.30.253.113)'"

While attempting to update my version of TypeScript using npm, I ran into an issue when trying to execute the following command: localhost:Pastebin davea$ npm install typescript/2.8.4 --save-dev The authenticity of host 'github.com (192.30.253.113)&a ...

Ways to transform a String into an Array using Java

Is there a way to convert a String into a String array without relying on a JsonObject in Java? I've searched extensively but haven't found a solution that works for me. The String that I have is similar to: String str="[{"India":{"State":" ...

What is the most efficient way to convert a String to an Integer[][][] array?

Typically, the files I deal with come in the following format: {0 0},{0 0} {0 0 0 0},{0 0 0 0},{0 0 0 0},{0 0 0 0} Thus, I require an Integer[][][] to store an array of matrices. My initial attempt looked like this: String path = "file.txt"; Str ...

Incorporating Java project dependencies into an npm project

I'm facing a challenge in my development process, where I need to incorporate dependencies from a Maven Java project into my package.json file within my Vue/Typescript project. These dependencies are crucial for accessing specific data types that my p ...

I must implement a pause in my automation script until I receive a response from an Angular HTTP request using Selenium with Java

I am a beginner in using Selenium. I'm currently working on creating a script that will log in to my website, navigate dropdown menus, click buttons, and then wait for the response of an Angular HTTP request before logging out. driver = new Chrom ...

What could be causing the conditional div to malfunction in Angular?

There are three conditional div elements on a page, each meant to be displayed based on specific conditions. <div *ngIf="isAvailable=='true'"> <form> <div class="form-group"> <label for ...

The NGINX reverse proxy fails to forward requests to an Express application

I am currently in the process of setting up a dedicated API backend for a website that operates on /mypath, but I am encountering issues with NGINX not properly proxying requests. Below is the nginx configuration located within the sites-enabled directory ...

Assessing the validity of a boolean condition as either true or false while iterating through a for loop

I am facing an issue that involves converting a boolean value to true or false if a string contains the word "unlimited". Additionally, I am adding a subscription to a set of values and need to use *NgIf to control page rendering based on this boolean. &l ...