Access to JPA data with REST error. No suitable HttpMessageConverter found.

I struggled with this for a while and could not find a solution. I run SpringBoot guides and accessing JPA data ( http://spring.io/guides/gs/accessing-data-rest/ ) with REST does not work.

Just downloading it and running it works great, allowing a GET call

http://localhost:8080/people 

using postman. However, whenever I try to execute PUT or POST, I get the following error:

 { "cause": null, "message": "No suitable HttpMessageConverter found to read request body into object of type class hello.Person from request with content type of text/plain;charset=UTF-8!" } 

json which I pass using PUT,

 { "firstName": "Dave", "lastName": "Something" } 

This is just a vanilla project with no changes. Many other manual projects work fine, so I know that MVN, Spring boot, etc. They work fine.

Tried a lot of forums, but nothing was offered.

Any help would be greatly appreciated.

Thanks Dave

+6
source share
3 answers

Your POST request is of the text/plain content type, and the server does not know how to convert plain text to a hello.Person instance.

You need to tell the server that you are sending JSON by setting the Content-Type header of the request to application/json

+17
source

I used the google chrome Postman extension and sent RAW JSON {"firstName": "Frodo", "lastName": "Baggins"} and it worked

also do not specify Content-Type: application / json in the header

+3
source

Content-Type: application / json tries to remove the space between the content type: * and the application in the header.

0
source

Source: https://habr.com/ru/post/978647/


All Articles