Skip to content

Commit

Permalink
#397 - Support for null complex objects in json composite storages.
Browse files Browse the repository at this point in the history
  • Loading branch information
maraf committed Jul 6, 2021
1 parent 92bdf8d commit aaa38a4
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -183,6 +183,11 @@ public bool TryGet<T>(string key, out T value)
}

JsonElement element = (JsonElement)target;
if (element.ValueKind == JsonValueKind.Null)
{
value = default(T);
return true;
}

if (typeof(T) == typeof(string))
{
Expand Down
6 changes: 6 additions & 0 deletions src/Neptuo.Json/Formatters/Converters/JsonObjectConverter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,12 @@ public bool TryConvert(Type sourceType, Type targetType, object sourceValue, out

private bool TryConvertFromJson(Type targetType, JToken sourceValue, out object targetValue)
{
if (sourceValue.Type == JTokenType.Null)
{
targetValue = null;
return true;
}

targetValue = JsonConvert.DeserializeObject(sourceValue.ToString(), targetType);
return targetValue != null;
}
Expand Down

0 comments on commit aaa38a4

Please sign in to comment.