0

Will be happy if somebody pays attention and helps me to solve this issue.

Rest server:

@RestController
@RequestMapping("/")
public class RestServer {

    @RequestMapping(value = "/foo/{bar}", method=RequestMethod.GET)
    @ResponseBody
    public List<UserEntity> getUsers(@PathVariable("bar") List<Object> criterions){
        return UserService.getInstance().getUserList(criterions);
    }

}

Rest client method:

public static void initUserMap(){

    List<Object> criterions = new ArrayList<>();
    criterions.add(Restrictions.eq("UserTypeId", 1));

    final String url = "http://localhost:8080/getUsers/" + criterions;
    RestTemplate restTemplate = new RestTemplate();
    List<UserEntity> users = restTemplate.getForObject(url, UserEntity.class);
    ..........
    ..........
}

Cannot compile because of the error I get:

Error:(71, 62) java: incompatible types: inference variable T has incompatible bounds
equality constraints: testRest.UserEntity upper bounds: java.util.List<testRest.UserEntity>,java.lang.Object

How do I pass criterions from client method as a parameter to getUsers method in the server, so I get result, which is also a list of users?

Thanks in advance.

zlekonis
  • 31
  • 6
  • Possible duplicate of [Get list of JSON objects with Spring RestTemplate](https://stackoverflow.com/questions/23674046/get-list-of-json-objects-with-spring-resttemplate) – Bennett Dams Aug 01 '18 at 11:32

1 Answers1

-1

In your rest client, you specified that the response will be of type UserEntity but you declared a variable of type List to hold the response. Change the response type to List.class

List<UserEntity> users = restTemplate.getForObject(url, List.class);
Elgayed
  • 1,129
  • 9
  • 16
  • I get this then: 16:16:59.786 [main] DEBUG org.springframework.web.client.RestTemplate - Created GET request for "http://localhost:8080/getUsers/%5BUserTypeId=1%5D" 16:16:59.821 [main] DEBUG org.springframework.web.client.RestTemplate - Setting request Accept header to [application/json, application/*+json] 16:17:03.152 [main] DEBUG org.springframework.web.client.RestTemplate - GET request for "http://localhost:8080/getUsers/%5BUserTypeId=1%5D" resulted in 500 (null); invoking error handler org.springframework.web.client.HttpServerErrorException: 500 null – zlekonis Jul 31 '18 at 13:20
  • The answer was for the compilation error that you posted, now your problem is that you can't pass a list as a path variable like that, you need to pass your criterions list as query parameters – Elgayed Jul 31 '18 at 13:24