Guest User

Untitled

a guest
Apr 23rd, 2018
202
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.58 KB | None | 0 0
  1. class DemoApplication {
  2. static void main(String[] args) {
  3. SpringApplication.run DemoApplication, args
  4. }
  5. @PostMapping("/")
  6. String greet(@RequestBody Greeting greeting) {
  7. return "Hello ${greeting.name}, with email ${greeting.email}"
  8. }
  9. }
  10.  
  11. @JsonInclude(JsonInclude.Include.NON_NULL)
  12. class Greeting {
  13. String name
  14. String email
  15. }
  16.  
  17. class DemoApplication {
  18. static void main(String[] args) {
  19. SpringApplication.run DemoApplication, args
  20. }
  21. @PostMapping("/")
  22. String greet(@RequestBody Greeting greeting) {
  23. return "Hello ${greeting.name}, with email ${greeting.email}"
  24. }
  25. }
  26.  
  27. class Greeting {
  28. String name
  29. String email
  30. }
  31.  
  32. ~ curl -H "Content-Type: application/json" -X POST localhost:8080
  33. {"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":"/"}
  34. ~ curl -H "Content-Type: application/json" -X POST localhost:8080 -d '{}'
  35. Hello null, with email null
  36. ~ curl -H "Content-Type: application/json" -X POST localhost:8080 -d '{"name": "AlejoDev"}'
  37. Hello AlejoDev, with email null
  38. ~ curl -H "Content-Type: application/json" -X POST localhost:8080 -d '{"name": "AlejoDev", "email":"info@alejodev.com"}'
  39. Hello AlejoDev, with email info@alejodev.com
  40.  
  41. ~ curl -H "Content-Type: application/json" -X POST localhost:8080 -d '{"name": "AlejoDev"}'
Add Comment
Please, Sign In to add comment