Posting JSON to REST API

后端 未结 9 837
-上瘾入骨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

    If I recall correctly the Spring docs say that Spring MVC will automatically detect Jackson on the classpath and set up a MappingJacksonHttpMessageConverter to handle conversion to/from JSON, but I think I have experienced situations where I had to manually/explictly configure that converter to get things to work. You may want to try adding this to your MVC config XML:

    
        
            
                
            
        
    
    

    UPDATE: It was this plus properly formatting the JSON being posted, see https://stackoverflow.com/a/10363876/433789

提交回复
热议问题