I am using :
- spring data rest
- lombok
When I receive my entity in my controller
@PostMapping
@ResponseStatus(HttpStatus.CREATED)
Long create(@RequestBody Blog blog) {
blogService.insert(blog);
return blog.getId();
}
I only set the blog name, however, Blog.java
contains default values:
private Boolean isDisabled = false;
private Boolean canCreateTags = true;
private Boolean canCreateCategories = true;
private Boolean hasRss = false;
This is the request body of my request :
{"organization":{"id":"1"},"description":"test"}
All the unsend values appear to be null
.
However when I use the BlogDTO
instead of Blog
:
@PostMapping
@ResponseStatus(HttpStatus.CREATED)
Long create(@RequestBody BlogDTO blog) {
blogService.insert(blog);
return blog.getId();
}
All the values are set with defaults.
- Why is the instance not created with my defaults?
- Why is the DTO instance created with defaults?