SMAPI - Stardew Modding API

SMAPI - Stardew Modding API

971k Downloads

Don't merge config.json collections when deserialising

Pathoschild opened this issue ยท 1 comments

commented

Use Json.NET's ObjectCreationHandling.Replace behaviour instead of the default, which is confusing.

Background

SMAPI 1.0+ uses the default Json.NET behaviour, which handles a conflict between a deserialised and default collection by merging them.

For example, let's say you have this:

  • Config model:
    class ModConfig
    {
       public List<int> Values { get; set; } = new List<int> { 1 };
    }
  • config.json:
    {
       "Values": [ 2 ]
    }

After helper.ReadConfig<ModConfig>(), most developers expect the value to be [ 2 ] because the config.json values intuitively override the defaults. The actual result is [ 1, 2 ] because Json.NET merges ICollection<T> values by default.

The ObjectCreationHandling.Replace behaves more intuitively, by only using the default values when the equivalent field is missing.

commented

Fixed in develop for the upcoming 1.6 release.