I have a JSON object which may contain a few null
values.
I use ObjectMapper
from com.fasterxml.jackson.databind
to convert my JSON object as String
.
private ObjectMapper mapper = new ObjectMapper();
String json = mapper.writeValueAsString(object);
If my object contains any field that contains a value as null
, then that field is not included in the String
that comes from writeValueAsString()
.
I want my ObjectMapper
to give me all fields in the String
even if their value is null
.
Example:
object = {"name": "John", "id": 10}
json = {"name": "John", "id": 10}
object = {"name": "John", "id": null}
json = {"name": "John"}