Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Accessing JPA Data with REST fails No suitable HttpMessageConverter found

I have been battling with this for a while and cant find a solution. I am running the SpringBoot guides and the Accessing JPA Data (http://spring.io/guides/gs/accessing-data-rest/) with REST is not working.

Just downloading it and running it runs fine allowing a GET call to

http://localhost:8080/people 

using POSTMAN. However whenever I try a 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!"
}

The json I am passing with the PUT is

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

This is just running the vanilla project with no changes. Lots of the other guide projects work fine so I know MVN, Spring boot etc are working ok.

Have tried a lot of forums but nothing suggested works.

Any help would be greatly appreciated.

Thanks Dave

like image 517
David Gildea Avatar asked Nov 24 '14 22:11

David Gildea


2 Answers

Your POST request has a content type of text/plain and the server doesn't know how to convert plain text into a hello.Person instance.

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

like image 193
Andy Wilkinson Avatar answered Sep 19 '22 13:09

Andy Wilkinson


I used Google Chrome's Postman extension and sent raw JSON { "firstName": "Frodo", "lastName": "Baggins" }. That worked.

Keep in mind to specify the HTTP header Content-Type: application/json.

like image 45
Byorn Avatar answered Sep 19 '22 13:09

Byorn