Reputation: 11
Im using Spring Boot 2.1.2.RELEASE together with Angular 7 and MongoDB.
Im writing a service where i want to create a new DB entry but I get an error message from Spring Boot saying JSON parse error: null spring boot.
The problem is that when Angular is creating the JSON which is sent in the request it includes all values that are null as { id: null, ... } I have tried to find a solution to my issue, but the answers i found isn't that satisfying for me.
Build the JSON string manually in Angular and exclude all parameters that are null. (for complex object where serveral values can be null this is not a nice solution
Add the following config to get jackson to understand that it should interpritade this as a null value:
spring.jackson.default-property-inclusion=NON_NULL
or
spring.jackson.default-property-inclusion=non_null
This does not work for me. Still the same problem.
Does anyone have any suggestion of how to solve this issue?
Thanks!
Upvotes: 1
Views: 1315
Reputation: 9806
You can use @JsonInclude
annotation like this:
@JsonInclude(Include.NON_NULL)
public class MyViewModel { ... }
If you want you can also apply on property granularity:
public class MyViewModel {
@JsonInclude(Include.NON_NULL)
private String value;
...
}
Upvotes: 1