How to not send an empty collection in jackson

后端 未结 2 1326
攒了一身酷
攒了一身酷 2021-01-01 14:09

I have an object that is curently being serialized to:

{
  \"label\" : \"label\",
  \"proxyIds\" : [ ],
  \"childIds\" : [ 161, 204, 206, 303, 311 ],
  \"act         


        
2条回答
  •  夕颜
    夕颜 (楼主)
    2021-01-01 14:13

    Since Jackson 2.0.0 (25-Mar-2012), you can also use the @JsonInclude annotation to control this on a per-field or per-class basis.

    public class MyObject {
    
        @JsonInclude(Include.NON_EMPTY)
        private List proxyIds;
    
        ...
    }
    

提交回复
热议问题