I have just started using Newtonsoft.Json (Json.net). In my first simple test, I ran into a problem when deserializing generic lists. In my code sample below I serialize an obje
That is because you are adding items in the constructor. A common approach in deserializers when processing a list is basically:
Add
) to the listthis is because most list members don't have setters, i.e.
public List Items {get {...}} // <=== no set
Contrast to arrays, which must have a setter to be useful; hence the approach is usually:
Add
) to a temporary listToArray
), and assign via the setterSome serializers give you options to control this behavior (others don't); and some serializers give you the ability to bypass the constructor completely (others don't).