briandilley/jsonrpc4j

JsonRpcServer request exception java.util.LinkedHashMap cannot be cast XXX

hi-mamba opened this issue · 0 comments

my JsonRpcService method param is List,this exception occurs when I execute unit tests, how does jackson set up?

I use the parameters in the postman request interface and there is no problem

curl --location --request POST 'http://localhost:8080/rpc/user' \
--header 'Content-Type: application/json' \
--data '{"method":"testUser","id":"0","jsonrpc":"2.0","params":[[{"id":94540,"code":"1"}]]}'

this is my interface

  @JsonRpcService(value = "rpc/user")
  public interface UserService {
   List<UserDTO>> testUser(List<User> userList);
   }

test case

        @Resource
        private UserRpcService userRpcService;

        ObjectMapper objectMapper = new ObjectMapper();
        JsonRpcServer jsonRpcServer = new JsonRpcServer(objectMapper,userRpcService);

        User user = new User();
        user.setId(1);
        user.setCode("1")
        List<User> userList = new ArrayList<>();
        userList.add(user);
        List<List<User>> list = new ArrayList<>();	
        list.add(userList);

        Map<String,Object> map = new HashMap();
        map.put("method","testUser");
        map.put("jsonrpc","2.0");
        map.put("id","1");
        map.put("params",list);

 	MockHttpServletRequest request = new MockHttpServletRequest("POST", "rpc/user");
        request.setContentType(MediaType.APPLICATION_JSON_VALUE);
        request.setCharacterEncoding(StandardCharsets.UTF_8.name());
        MockHttpServletResponse response = new MockHttpServletResponse();
        request.setContent(map.toString.getBytes(StandardCharsets.UTF_8));
        
        jsonRpcServer.handle(request, response);

        response.setCharacterEncoding(StandardCharsets.UTF_8.name());

jsonrpc4j version: 2.2.4-alpha