How to make Json.Net skip serialization of empty collections

前端 未结 2 961
攒了一身酷
攒了一身酷 2020-12-06 10:47

I have an object that contains several properties that are a List of strings List or a dictionary of strings Dictionary

2条回答
  •  盖世英雄少女心
    2020-12-06 11:42

    Another very simple solution is to implement a ShouldSerialize* method in the type being serialized as outline here.

    This might be the preferred way if you're in control of the type being serialized and if it is not a general behavior you want to introduce.

提交回复
热议问题