Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- class DemoApplication {
- static void main(String[] args) {
- SpringApplication.run DemoApplication, args
- }
- @PostMapping("/")
- String greet(@RequestBody Greeting greeting) {
- return "Hello ${greeting.name}, with email ${greeting.email}"
- }
- }
- @JsonInclude(JsonInclude.Include.NON_NULL)
- class Greeting {
- String name
- String email
- }
- class DemoApplication {
- static void main(String[] args) {
- SpringApplication.run DemoApplication, args
- }
- @PostMapping("/")
- String greet(@RequestBody Greeting greeting) {
- return "Hello ${greeting.name}, with email ${greeting.email}"
- }
- }
- class Greeting {
- String name
- String email
- }
- ~ curl -H "Content-Type: application/json" -X POST localhost:8080
- {"timestamp":"2018-04-22T21:18:39.849+0000","status":400,"error":"Bad Request","message":"Required request body is missing: public java.lang.String com.example.demo.DemoApplication.greet(com.example.demo.Greeting)","path":"/"}
- ~ curl -H "Content-Type: application/json" -X POST localhost:8080 -d '{}'
- Hello null, with email null
- ~ curl -H "Content-Type: application/json" -X POST localhost:8080 -d '{"name": "AlejoDev"}'
- Hello AlejoDev, with email null
- ~ curl -H "Content-Type: application/json" -X POST localhost:8080 -d '{"name": "AlejoDev", "email":"info@alejodev.com"}'
- Hello AlejoDev, with email info@alejodev.com
- ~ curl -H "Content-Type: application/json" -X POST localhost:8080 -d '{"name": "AlejoDev"}'
Add Comment
Please, Sign In to add comment