I have a JSON object that can contain multiple null values. I am using ObjectMapper from com.fasterxml.jackson.databind to convert my JSON object to String.
private ObjectMapper mapper = new ObjectMapper(); String json = mapper.writeValueAsString(object);
If my object contains any field containing a value as null, then this field is not on the line that comes from writeValueAsString. I want my ObjectMapper to give me all the fields in a 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"}
java json string jackson
LINGS
source share