From 11d232cf55cd6f8a59b4fe91def559808537ca8b Mon Sep 17 00:00:00 2001 From: Sebastian Date: Tue, 3 Aug 2021 12:15:03 +0200 Subject: [PATCH] Do not write null values. --- .../FileSystem/Default/DefaultFile.cs | 2 +- .../Commands/Implementation/Sync/SyncService.cs | 15 ++++++++------- cli/Squidex.CLI/Squidex.CLI/Squidex.CLI.csproj | 2 +- 3 files changed, 10 insertions(+), 9 deletions(-) diff --git a/cli/Squidex.CLI/Squidex.CLI/Commands/Implementation/FileSystem/Default/DefaultFile.cs b/cli/Squidex.CLI/Squidex.CLI/Commands/Implementation/FileSystem/Default/DefaultFile.cs index 36509564..cbce28eb 100644 --- a/cli/Squidex.CLI/Squidex.CLI/Commands/Implementation/FileSystem/Default/DefaultFile.cs +++ b/cli/Squidex.CLI/Squidex.CLI/Commands/Implementation/FileSystem/Default/DefaultFile.cs @@ -38,7 +38,7 @@ public Stream OpenWrite() { Directory.CreateDirectory(fileInfo.Directory.FullName); - return fileInfo.OpenWrite(); + return new FileStream(fileInfo.FullName, FileMode.Create, FileAccess.Write); } public override string ToString() diff --git a/cli/Squidex.CLI/Squidex.CLI/Commands/Implementation/Sync/SyncService.cs b/cli/Squidex.CLI/Squidex.CLI/Commands/Implementation/Sync/SyncService.cs index 28770854..883371eb 100644 --- a/cli/Squidex.CLI/Squidex.CLI/Commands/Implementation/Sync/SyncService.cs +++ b/cli/Squidex.CLI/Squidex.CLI/Commands/Implementation/Sync/SyncService.cs @@ -50,6 +50,7 @@ public SyncService(IFileSystem fileSystem) jsonSerializerSettings.Converters.Add(new StringEnumConverter()); jsonSerializerSettings.Formatting = Formatting.Indented; + jsonSerializerSettings.NullValueHandling = NullValueHandling.Ignore; jsonSchemaGeneratorSettings = new JsonSchemaGeneratorSettings { @@ -74,16 +75,16 @@ public SyncService(IFileSystem fileSystem) })); jsonSerializer = JsonSerializer.Create(jsonSerializerSettings); + FileSystem = fileSystem; } public T Read(IFile file, ILogger log) { - var json = file.ReadAllText(); - - var schema = GetSchema(); + var jsonText = file.ReadAllText(); + var jsonSchema = GetSchema(); - var errors = schema.Validate(json); + var errors = jsonSchema.Validate(jsonText); if (errors.Any()) { @@ -104,7 +105,7 @@ public T Read(IFile file, ILogger log) throw new JsonException($"Error reading file {file.FullName}"); } - return JsonConvert.DeserializeObject(json, jsonSerializerSettings); + return JsonConvert.DeserializeObject(jsonText, jsonSerializerSettings); } public Task WriteWithSchemaAs(IFile file, object sample, string schema) where T : class @@ -133,9 +134,9 @@ public Task WriteJsonSchemaAsync(IFile file) { using (var textWriter = new StreamWriter(stream)) { - var schema = GetSchema(); + var jsonSchema = GetSchema(); - textWriter.Write(schema.ToJson()); + textWriter.Write(jsonSchema.ToJson()); } } diff --git a/cli/Squidex.CLI/Squidex.CLI/Squidex.CLI.csproj b/cli/Squidex.CLI/Squidex.CLI/Squidex.CLI.csproj index 9718a433..bc96b77c 100644 --- a/cli/Squidex.CLI/Squidex.CLI/Squidex.CLI.csproj +++ b/cli/Squidex.CLI/Squidex.CLI/Squidex.CLI.csproj @@ -14,7 +14,7 @@ net5.0 true sq - 7.10 + 7.11