How to avoid null values serialization in HashMap?

前端 未结 5 628
夕颜
夕颜 2021-01-04 06:19

I would like to serialize a HashMap as a string through the Jackson JSON processor. For example:

String strMap = getMapper().writeValueAsString(myHashMap);
r         


        
5条回答
  •  自闭症患者
    2021-01-04 07:14

    Using Jackson 2.1.2 I have found that I can annotate the class with @JsonInclude(Include.NON_NULL) so that nulls are not serialized at all.

提交回复
热议问题