Skip to content

Instantly share code, notes, and snippets.

@peanutpi
Created June 20, 2018 11:57
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save peanutpi/2c40389695bb0890957b5d70204d8987 to your computer and use it in GitHub Desktop.
Save peanutpi/2c40389695bb0890957b5d70204d8987 to your computer and use it in GitHub Desktop.
package com.example.jacksondemo.dto;
import java.time.LocalDate;
import java.util.ArrayList;
import java.util.List;
import javax.validation.constraints.NotNull;
import javax.validation.constraints.Size;
public class Message {
private Long id;
private LocalDate created;
private String title;
private User author;
private String body = "hola!";
public Long getId() {
return id;
}
public void setId(Long id) {
this.id = id;
}
public LocalDate getCreated() {
return created;
}
public void setCreated(LocalDate created) {
this.created = created;
}
public String getTitle() {
return title;
}
public void setTitle(String title) {
this.title = title;
}
public User getAuthor() {
return author;
}
public void setAuthor(User author) {
this.author = author;
}
public String getBody() {
return body;
}
public void setBody(String body) {
this.body = body;
}
}
package com.example.jacksondemo.rest;
import javax.validation.Valid;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController;
import com.example.jacksondemo.dto.Message;
@RestController
public class MessageController {
@PostMapping("/")
public void createMessage(@Valid @RequestBody Message message) {
System.out.println("Success ! " + message.getBody());
}
}
curl -X POST \
http://localhost:8080/ \
-H 'cache-control: no-cache' \
-H 'content-type: application/json' \
-d '{
"title": "abc"
}'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment