1

How can I render a null element of a list as empty element in a json POST response?

@PostMapping("/")
@ResponseBody
public MyRsp test() {
    MyRsp rps = new MyRsp();
    rsp.setList(Arrays.asList("one", "two", null, "four");
    return rsp;  

}

@JsonInclude(Include.NON_NULL)
public class MyRsp {
    @JsonInclude(Include.NON_NULL)
    private List<String> list;
}

Result:

{
   list: [
     "one",
     "two",
     null,
     "four"
   ]
}

I'm already using the following property:

spring.jackson.default-property-inclusion=non_null.

What else could I do?

membersound
  • 81,582
  • 193
  • 585
  • 1,120

0 Answers0