Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
hi-mamba opened this issue Apr 13, 2022 · 0 comments
Open

Comments

@hi-mamba
Copy link

hi-mamba commented Apr 13, 2022

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant