I checked in several different ways, also downloaded a new project to see what to check where is bug but I still do not know the answer.
That is my RestController
@RestController
@RequestMapping(value = "/message")
public class MessageController {
@RequestMapping(value = "/", method = RequestMethod.POST)
public void createMessage(@RequestBody Message message){
System.out.println(message);
}
}
That is my Model
@Data
@Entity
public class Message {
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
private long id;
private String sender;
private String telephone;
private String message;
}
Gradle dependencies if necessary
dependencies {
compile group: 'com.fasterxml.jackson.core', name: 'jackson-core', version: '2.9.0.pr3'
compile('org.springframework.boot:spring-boot-starter-data-jpa')
compile('org.springframework.boot:spring-boot-starter-web')
runtime('com.h2database:h2')
runtime('org.postgresql:postgresql')
compileOnly('org.projectlombok:lombok')
testCompile('org.springframework.boot:spring-boot-starter-test')
}
and in postman i'm getting that error
{ "timestamp": 1495992553884, "status": 415, "error": "Unsupported Media Type", "exception": "org.springframework.web.HttpMediaTypeNotSupportedException",
"message": "Content type 'application/x-www-form-urlencoded;charset=UTF-8' not supported",
"path": "/message/" }
It is simplest way for rest but where I make a mistake?
@RequestBody
is for getting the full body and transform that into that object. However judging from your error you are simply posting a form then you should use@ModelAttribute
instead, this is used for binding request parameters to objects. – M. Deinum@RequestBody InputStream
, tryInputStreamResource
instead – Janaka Bandara