Deserialize Json, CreateInstance is called for already initialized collection properties

In my constructor i’m inititialising some (ICollection) collections, but during deserialization the collection is re-created using the base constructor of the type.

public class Country : LookupItem {
		public Country() {
			Provinces = new EmbeddedList<Province>(this);
			Cultures = new EmbeddedItems<System.Globalization.CultureInfo>(this);
		}

		public EmbeddedList<Province> Provinces { get; private set; }

I’m storing the reference to the “owning” object in the collection, but due to the CreateInstance in the CollectionExtensions.CreateAndPopulate the collection is re-created. Shouldn’t this be skipped when the collection is not null and call collection.clear() before adding the items?

Note: you shouldn’t have any cyclical references in DTOs and no deserialization dehydrates a DTO from a payload, it doesn’t call Clear() to mutate existing collections.

This is not a DTO class, this is the database model class where some properties are stored as jsonb objects in the (postgresql) database and serialized/deserialized by OrmLite. The backreference is marked as IgnoreDataMember to prevent cyclical references.

Doesn’t matter what the role of the class is, if it’s being deserialized it shouldn’t have cyclical deps. Regardless, it’s not the issue here.