From 5d1cd0b171129847505f553b2aae69c04d74af81 Mon Sep 17 00:00:00 2001 From: Paul Hebble Date: Thu, 9 Nov 2017 17:24:20 -0600 Subject: [PATCH] Tell serializer to ignore nulls in registry --- Core/Registry/InstalledModule.cs | 9 ++++--- Core/Types/CkanModule.cs | 39 +++++++++++++++------------ Core/Types/ModuleInstallDescriptor.cs | 16 +++++------ 3 files changed, 35 insertions(+), 29 deletions(-) diff --git a/Core/Registry/InstalledModule.cs b/Core/Registry/InstalledModule.cs index 63347bb9a8..af675165db 100644 --- a/Core/Registry/InstalledModule.cs +++ b/Core/Registry/InstalledModule.cs @@ -13,7 +13,8 @@ public class InstalledModuleFile // TODO: This class should also record file paths as well. // It's just sha1 now for registry compatibility. - [JsonProperty] private string sha1_sum; + [JsonProperty("sha1_sum", NullValueHandling = NullValueHandling.Ignore)] + private string sha1_sum; public string Sha1 { @@ -64,7 +65,7 @@ private static string Sha1Sum(string path) /// /// A simple class that represents an installed module. Includes the time of installation, /// the module itself, and a list of files installed with it. - /// + /// /// Primarily used by the Registry class. /// @@ -89,7 +90,7 @@ public class InstalledModule // registry format compatibility. [JsonProperty] private Dictionary installed_files; - public IEnumerable Files + public IEnumerable Files { get { return installed_files.Keys; } } @@ -162,4 +163,4 @@ public void Renormalise(KSP ksp) #endregion } -} \ No newline at end of file +} diff --git a/Core/Types/CkanModule.cs b/Core/Types/CkanModule.cs index 9bd1798286..1467286ac0 100644 --- a/Core/Types/CkanModule.cs +++ b/Core/Types/CkanModule.cs @@ -72,18 +72,23 @@ public string RequiredVersion public class ResourcesDescriptor { + [JsonProperty("repository", NullValueHandling = NullValueHandling.Ignore)] [JsonConverter(typeof(JsonIgnoreBadUrlConverter))] public Uri repository; + [JsonProperty("homepage", NullValueHandling = NullValueHandling.Ignore)] [JsonConverter(typeof(JsonIgnoreBadUrlConverter))] public Uri homepage; + [JsonProperty("bugtracker", NullValueHandling = NullValueHandling.Ignore)] [JsonConverter(typeof(JsonIgnoreBadUrlConverter))] public Uri bugtracker; + [JsonProperty("spacedock", NullValueHandling = NullValueHandling.Ignore)] [JsonConverter(typeof(JsonOldResourceUrlConverter))] public Uri spacedock; + [JsonProperty("curse", NullValueHandling = NullValueHandling.Ignore)] [JsonConverter(typeof(JsonOldResourceUrlConverter))] public Uri curse; } @@ -141,24 +146,24 @@ public class CkanModule : IEquatable [JsonProperty("abstract")] public string @abstract; - [JsonProperty("description")] + [JsonProperty("description", NullValueHandling = NullValueHandling.Ignore)] public string description; // Package type: in spec v1.6 can be either "package" or "metapackage" - [JsonProperty("kind")] + [JsonProperty("kind", NullValueHandling = NullValueHandling.Ignore)] public string kind; - [JsonProperty("author")] + [JsonProperty("author", NullValueHandling = NullValueHandling.Ignore)] [JsonConverter(typeof(JsonSingleOrArrayConverter))] public List author; - [JsonProperty("comment")] + [JsonProperty("comment", NullValueHandling = NullValueHandling.Ignore)] public string comment; - [JsonProperty("conflicts")] + [JsonProperty("conflicts", NullValueHandling = NullValueHandling.Ignore)] public List conflicts; - [JsonProperty("depends")] + [JsonProperty("depends", NullValueHandling = NullValueHandling.Ignore)] public List depends; [JsonProperty("download")] @@ -167,19 +172,19 @@ public class CkanModule : IEquatable [JsonProperty("download_size")] public long download_size; - [JsonProperty("download_hash")] + [JsonProperty("download_hash", NullValueHandling = NullValueHandling.Ignore)] public DownloadHashesDescriptor download_hash; [JsonProperty("identifier", Required = Required.Always)] public string identifier; - [JsonProperty("ksp_version")] + [JsonProperty("ksp_version", NullValueHandling = NullValueHandling.Ignore)] public KspVersion ksp_version; - [JsonProperty("ksp_version_max")] + [JsonProperty("ksp_version_max", NullValueHandling = NullValueHandling.Ignore)] public KspVersion ksp_version_max; - [JsonProperty("ksp_version_min")] + [JsonProperty("ksp_version_min", NullValueHandling = NullValueHandling.Ignore)] public KspVersion ksp_version_min; [JsonProperty("ksp_version_strict")] @@ -192,28 +197,28 @@ public class CkanModule : IEquatable [JsonProperty("name")] public string name; - [JsonProperty("provides")] + [JsonProperty("provides", NullValueHandling = NullValueHandling.Ignore)] public List provides; - [JsonProperty("recommends")] + [JsonProperty("recommends", NullValueHandling = NullValueHandling.Ignore)] public List recommends; - [JsonProperty("release_status")] + [JsonProperty("release_status", NullValueHandling = NullValueHandling.Ignore)] public ReleaseStatus release_status; - [JsonProperty("resources")] + [JsonProperty("resources", NullValueHandling = NullValueHandling.Ignore)] public ResourcesDescriptor resources; - [JsonProperty("suggests")] + [JsonProperty("suggests", NullValueHandling = NullValueHandling.Ignore)] public List suggests; [JsonProperty("version", Required = Required.Always)] public Version version; - [JsonProperty("supports")] + [JsonProperty("supports", NullValueHandling = NullValueHandling.Ignore)] public List supports; - [JsonProperty("install")] + [JsonProperty("install", NullValueHandling = NullValueHandling.Ignore)] public ModuleInstallDescriptor[] install; // Used to see if we're compatible with a given game/KSP version or not. diff --git a/Core/Types/ModuleInstallDescriptor.cs b/Core/Types/ModuleInstallDescriptor.cs index 0e1b9a7159..2d834d8d0a 100644 --- a/Core/Types/ModuleInstallDescriptor.cs +++ b/Core/Types/ModuleInstallDescriptor.cs @@ -17,13 +17,13 @@ public class ModuleInstallDescriptor : ICloneable #region Properties // Either file, find, or find_regexp is required, we check this manually at deserialise. - [JsonProperty("file")] + [JsonProperty("file", NullValueHandling = NullValueHandling.Ignore)] public string file; - [JsonProperty("find")] + [JsonProperty("find", NullValueHandling = NullValueHandling.Ignore)] public string find; - [JsonProperty("find_regexp")] + [JsonProperty("find_regexp", NullValueHandling = NullValueHandling.Ignore)] public string find_regexp; [JsonProperty("find_matches_files")] @@ -32,22 +32,22 @@ public class ModuleInstallDescriptor : ICloneable [JsonProperty("install_to", Required = Required.Always)] public string install_to; - [JsonProperty("as")] + [JsonProperty("as", NullValueHandling = NullValueHandling.Ignore)] public string @as; - [JsonProperty("filter")] + [JsonProperty("filter", NullValueHandling = NullValueHandling.Ignore)] [JsonConverter(typeof(JsonSingleOrArrayConverter))] public List filter; - [JsonProperty("filter_regexp")] + [JsonProperty("filter_regexp", NullValueHandling = NullValueHandling.Ignore)] [JsonConverter(typeof(JsonSingleOrArrayConverter))] public List filter_regexp; - [JsonProperty("include_only")] + [JsonProperty("include_only", NullValueHandling = NullValueHandling.Ignore)] [JsonConverter(typeof(JsonSingleOrArrayConverter))] public List include_only; - [JsonProperty("include_only_regexp")] + [JsonProperty("include_only_regexp", NullValueHandling = NullValueHandling.Ignore)] [JsonConverter(typeof(JsonSingleOrArrayConverter))] public List include_only_regexp;