How to avoid null values serialization in HashMap?

前端 未结 5 601
夕颜
夕颜 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:01

    With latest Jackson version, on the ObjectMapper, you can do:

    mapper.setSerializationInclusion(JsonInclude.Include.NON_NULL);

提交回复
热议问题