-Fixed merging null string values
This commit is contained in:
@@ -46,6 +46,16 @@ namespace Newtonsoft.Json.Tests.Linq
|
|||||||
[TestFixture]
|
[TestFixture]
|
||||||
public class MergeTests : TestFixtureBase
|
public class MergeTests : TestFixtureBase
|
||||||
{
|
{
|
||||||
|
[Test]
|
||||||
|
public void MergeNullString()
|
||||||
|
{
|
||||||
|
var a = new JObject { ["a"] = 1 };
|
||||||
|
var b = new JObject { ["a"] = false ? "2" : null };
|
||||||
|
a.Merge(b);
|
||||||
|
|
||||||
|
Assert.AreEqual(1, (int)a["a"]);
|
||||||
|
}
|
||||||
|
|
||||||
[Test]
|
[Test]
|
||||||
public void MergeObjectProperty()
|
public void MergeObjectProperty()
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -185,7 +185,7 @@ namespace Newtonsoft.Json.Linq
|
|||||||
{
|
{
|
||||||
if (!(existingProperty.Value is JContainer existingContainer) || existingContainer.Type != contentItem.Value.Type)
|
if (!(existingProperty.Value is JContainer existingContainer) || existingContainer.Type != contentItem.Value.Type)
|
||||||
{
|
{
|
||||||
if (contentItem.Value.Type != JTokenType.Null || settings?.MergeNullValueHandling == MergeNullValueHandling.Merge)
|
if (!IsNull(contentItem.Value) || settings?.MergeNullValueHandling == MergeNullValueHandling.Merge)
|
||||||
{
|
{
|
||||||
existingProperty.Value = contentItem.Value;
|
existingProperty.Value = contentItem.Value;
|
||||||
}
|
}
|
||||||
@@ -198,6 +198,21 @@ namespace Newtonsoft.Json.Linq
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private static bool IsNull(JToken token)
|
||||||
|
{
|
||||||
|
if (token.Type == JTokenType.Null)
|
||||||
|
{
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (token is JValue v && v.Value == null)
|
||||||
|
{
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
internal void InternalPropertyChanged(JProperty childProperty)
|
internal void InternalPropertyChanged(JProperty childProperty)
|
||||||
{
|
{
|
||||||
OnPropertyChanged(childProperty.Name);
|
OnPropertyChanged(childProperty.Name);
|
||||||
|
|||||||
Reference in New Issue
Block a user