According to third party API spec, I need to send null value in JSON using ObjectMapper
if no value exists,
Expected results : "optional": null
If optional value exists, then send "optional": "value"
I didn't find such option in Jackson – Working with Maps and nulls
Code:
requestVO = new RequestVO(optional);
ObjectMapper mapper = new ObjectMapper();
String requestString = mapper.writeValueAsString(requestVO);
Class:
public class RequestVO {
String optional;
public RequestVO(String optional) {
this.optional = optional;
}
public String getOptional() {
return optional;
}
public void setOptional(String optional) {
this.optional= optional;
}