Sorry for bad english.
I currently use dto for request body mapping,
Spring can not know input is null or not received, because both situation is just null.
As an example, Like this.
// dto
public class UpdateDto {
private String name;
private Integer price;
}
// entity
public class Product {
@Id
@GeneratedValue
private Long id;
@Column(nullable = true)
private String name;
@Column(nullable = true)
private Integer price;
}
I solved in string case using empty string. When empty string received, update this field to null. Because most of case empty string can treated as null.
// update name
if (updateDto.getName() != null) {
if (updateDto.getName() == "") {
// set name to null
} else {
// just update to getName() value
}
}
// update price
// when i set to null?
However integer case, I don't know how can i solve this problem. Anything good idea?