-1

I have this part of code:

  try {
            ResponseEntity<T> responseEntity = restTemplate.exchange(builder.build().encode().toUri(), HttpMethod.GET, null,
                    new ParameterizedTypeReference<T>() {
                    });

            if (responseEntity == null || responseEntity.getBody() == null || responseEntity.getBody() == null) {
                throw ApiException.createFrom(ResponseCode.REQUEST_INVALID, "Severity for this input is not found!");
            } else {
                return (LinkedHashMap<Object, Object>) responseEntity.getBody();

            }

Problem is that i always get 400 null error.

When i ask in swagger with filter parameter : [{"attribute":"tapId","filterOperation":"EQUALS","expressionValue":"00b83d4c-afad-47fb-b66b-07c93971c69b"}]

I get this url :

?filter=%5B%7B"attribute"%3A"tapId"%2C"filterOperation"%3A"EQUALS"%2C"expressionValue"%3A"00b83d4c-afad-47fb-b66b-07c93971c69b"%7D%5D

and this is working, but when i call it with this part of code:

 builder.queryParam("filter", String.join(",", filter));

and then

ResponseEntity<T> responseEntity = restTemplate.exchange(builder.build().encode().toUri(), HttpMethod.GET, null,
                        new ParameterizedTypeReference<T>() {
                        });

i get this url

?filter=%7B%22attribute%22:%22tapId%22,%22filterOperation%22:%22EQUALS%22,%22expressionValue%22:%2200b83d4c-afad-47fb-b66b-07c93971c69b%22%7D

and this is not working and im getting this error. Any suggestion how can i fix this?

uzhas
  • 895
  • 4
  • 13
  • 27

1 Answers1

2
%5B%7B"attribute"%3A"tapId"%2C"filterOperation"%3A"EQUALS"%2C"expressionValue"%3A"00b83d4c-afad-47fb-b66b-07c93971c69b"%7D%5D

This is the result of direct conversion of the filter parameter object.

String filterObject = "[{\"attribute\":\"tapId\",\"filterOperation\":\"EQUALS\",\"expressionValue\":\"00b83d4c-afad-47fb-b66b-07c93971c69b\"}]"

I think the following should work.

builder.queryParam("filter", filterObject);

Why I am thinking that?

Because %5B = [ and so on.

You may check this.

What does %5B and %5D in POST requests stand for?

uneq95
  • 2,158
  • 2
  • 17
  • 28
  • this is working, but problem is that my filter is "dynamic" , so that i call different filters for different services, is thare any way to make this "dynamic" ? – uzhas Jun 14 '20 at 20:14
  • Use a JSONArray to construct the filter. Convert it to string after that. – uneq95 Jun 14 '20 at 20:17
  • im not sure how to that because i have multiple "keys" ... can u give me some direction or example? im tying to find any but no success – uzhas Jun 14 '20 at 21:00
  • `{"attribute":"tapId",...}` is just a map(or use json object from any library). fill your parameters using key. put that into an array list or json array and use the toString value for the filteration – uneq95 Jun 14 '20 at 21:04