ResponseEntity : HTTP Status 400 – Bad Request

rasit

I have a web service that returns JSON. I am trying to print the screen using this web service spring mvc. The code I wrote is getting 400 errors. How can I resolve it?

I use json object:

{"currencyRates":[{"currencyPair":"BGN/IRR","date":1519922870105,"askPrice":4.376,"bidPrice":2.162},{"currencyPair":"ROL/LKR","date":1519922870105,"askPrice":4.056,"bidPrice":2.132},{"currencyPair":"KES/MGF","date":1519922870105,"askPrice":4.067,"bidPrice":3.005}]}

Controller:

@RequestMapping(value = "/list", method = RequestMethod.GET, produces = MediaType.APPLICATION_JSON_VALUE)
    public String userList(ModelMap model) {

        RestTemplate restTemplate = new RestTemplate();
        ResponseEntity<List<CurrencyRate>> rateResponse = restTemplate.exchange(
                "http://localhost:8080/denemeDenemeDeneme/rates", HttpMethod.GET, null,
                new ParameterizedTypeReference<List<CurrencyRate>>() {
                });
        List<CurrencyRate> rates = rateResponse.getBody();

        model.addAttribute("list", rates);
        return "list";
    }

Thanks...

JaisAnkit

The problem is that the target class which cannot be a non-static inner class. It doesn't work embedded in the Controller class which I think is the problem.

The details are in here but it boils down to the way Java added inner classes means they don't have the default constructor that Jackson requires.

or Check if your class CurrencyRates does have constructor without any parameter.

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

HTTP Status 400 – Bad Request - Hibernate

Getting HTTP Status 400 – Bad Request in post request in rest assured

Getting HTTP status 400-Bad Request REST

Very Simple AngularJS $http POST Results in '400 (Bad Request)' and 'Invalid HTTP status code 400'

HTTP POST -> 400: Bad Request

The request failed with HTTP status 400: Bad Request when calling web service from a windows application

AJAX call error - status of 400 (Bad Request)

How to fix "Bad Request","status":400"

Bad Request with 400 status code in Spring boot

Connect With PayPal : Get status 400 (Bad Request)

400 Bad Request error with HTTP multipart request

400 Bad Request in HTTP/1.1 but not in HTTP/1.0

iOS 17.0 Simulator (21A328) Failed with HTTP status 400: bad request

.Net HttpWebRequest.GetResponse() raises exception when http status code 400 (bad request) is returned

HTTP Status 400 – Bad Request when try to save Date to Data Base

Geopy Returns HTTP Error 400: Bad Request

HTTP CONNECT Tunnel reply with BAD Request (400)

nginx HTTP 400 Bad Request - Invalid Hostname

HTTP POST Returns 400 Bad Request

Php Curl HTTP/1.1 400 Bad Request

Create Contact returns HTTP 400 - Bad Request

HTTP Error 400 bad request python

C++ Http POST 400 bad request

400 Bad Request for $http post method

"status": 400, "error": "Bad Request", spring boot , Create request

HTTP request failed! HTTP/1.1 400 Bad Request

HTTP/1.1 400 Bad Request. Bad number of command parts

How to resolve "snapd returned status code 400: Bad Request"?

scrapy 400 bad request but status 200ok on postman