Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 19 additions & 5 deletions uSync.Core/Extensions/JsonTextExtensions.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using System.Diagnostics.CodeAnalysis;
using System.Buffers;
using System.Diagnostics.CodeAnalysis;
using System.Text.Json;
using System.Text.Json.Nodes;
using System.Text.Json.Serialization;
Expand Down Expand Up @@ -511,11 +512,24 @@ public static JsonArray GetPropertyAsArray(this JsonObject obj, string propertyN
/// tells us if the json for an object is equal, helps when the config objects don't have their
/// own Equals functions
/// </summary>
public static bool IsJsonEqual(this object currentObject, object newObject)
public static bool IsJsonEqual(this object? currentObject, object? newObject)
{
var currentString = currentObject.SerializeJsonString(false);
var newString = newObject.SerializeJsonString(false);
return currentString == newString;
if (currentObject is null && newObject is null)
return true;
if (currentObject is null)
return false;
if (newObject is null)
return false;

ArrayBufferWriter<byte> currentObjectBufferWriter = new();
using Utf8JsonWriter currentObjectUtf8JsonWriter = new(currentObjectBufferWriter);
JsonSerializer.Serialize(currentObjectUtf8JsonWriter, currentObject, _flatOptions);

ArrayBufferWriter<byte> newObjectBufferWriter = new();
using Utf8JsonWriter newObjectUtf8JsonWriter = new(newObjectBufferWriter);
JsonSerializer.Serialize(newObjectUtf8JsonWriter, newObject, _flatOptions);

return currentObjectBufferWriter.WrittenSpan.SequenceEqual(newObjectBufferWriter.WrittenSpan);
}

#endregion
Expand Down
Loading