Posting JSON to REST API

后端 未结 9 852
-上瘾入骨i
-上瘾入骨i 2020-12-08 08:12

I\'m creating a REST API that will accept JSON requests.

I\'m testing it out using CURL:

curl -i -POST -H \'Accept: application/json\' -d \'{\"id\":1         


        
9条回答
  •  陌清茗
    陌清茗 (楼主)
    2020-12-08 08:44

    I had the same problem, which was solved by two changes in my code :

    1. Missing @PathVariable in my method argument, my method didn't have any
    2. Following method in my SpringConfig class since the one I had with handler interceptor was deprecated and giving some issue:

      public RequestMappingHandlerAdapter RequestMappingHandlerAdapter()
      {
          final RequestMappingHandlerAdapter requestMappingHandlerAdapter = new RequestMappingHandlerAdapter();
          final MappingJacksonHttpMessageConverter mappingJacksonHttpMessageConverter = new MappingJacksonHttpMessageConverter();
          final String[] supportedHttpMethods = { "POST", "GET", "HEAD" };
      
          requestMappingHandlerAdapter.getMessageConverters().add(0, mappingJacksonHttpMessageConverter);
          requestMappingHandlerAdapter.setSupportedMethods(supportedHttpMethods);
      
          return requestMappingHandlerAdapter;
      }
      

提交回复
热议问题