I created the following REST API with Spring Boot.
@RestController
public class PersonController {
@Autowired
private PersonRepository PersonRepository;
@PostMapping(value="/Person", produces = "application/json")
public ResponseEntity<Person> addPerson(@RequestBody Person Person){
Person newPerson = PersonRepository.save(Person);
return new ResponseEntity<Person>(newPerson, HttpStatus.OK) ;
}
}
In Postman I select:
POST > http://localhost:8080/person > json
Then in the body field I place the following json and hit send:
{"id":"", "name":"john", "age":"40", "email":"[email protected]"}
This is the return I'm getting:
{
"name": "john",
"age": 40,
"email": "[email protected]",
"_links": {
"self": {
"href": "http://localhost:8080/person/10"
},
"person": {
"href": "http://localhost:8080/person/10"
}
}
}
But, I'd like to have the json return in this other format:
{
"id": 10,
"name": "john",
"age": 40,
"email": "[email protected]"
}
How to do that?
Personvs.person?_linksa part of your person entity? I tried to reproduce this but my response doesn't include the _links part that yours does.