Home > front end >  When returning VO as json, how to return excluding null value?
When returning VO as json, how to return excluding null value?

Time:11-08

When returning VO as json, how to return excluding null value?

     @RequestMapping("/rbtInfo.do")
     public RobotVO rbtInfo(@RequestParam String rbtId){
         String rbtPower = "ON";
         robot.setRbtPower(rbtPower);
         return robot;

     }

Above is my controller.

And the return value is as follows.

{
     "rbtId": null,
     "rbtPower": "ON",
     "rtspAddr": null,
     "ifrRtspAddr": null,
     "stationPosition": null,
}

In this case, I want to return only rbtPower for which the value exists, but not the rest.

How can I return excluding null data from VO?

CodePudding user response:

You can use below annotation at class level or method level for RobotVO.

@JsonInclude(Include.NON_NULL)

https://www.baeldung.com/jackson-ignore-null-fields

  • Related