Repository navigation
Closed
Labels
area-System.Text.Jsonbuggood first issueIssue should be easy to implement, good for first-time contributorshelp wanted[up-for-grabs] Good issue for external contributors
Milestone
Description
Hi,
I want to use an immutable dictionary to store json extension data.
I tried to see if this is supported by writing the following test in an mstest project targeting netcoreapp3.1:
[TestClass]
public sealed class JsonExtensionDataTest
{
class HasImmutableExtensionData
{
[JsonExtensionData]
public ImmutableDictionary<string, JsonElement> ExtensionData { get; set; }
}
[TestMethod]
public void Can_deserialize_immutable_extension_data()
{
const string json = "{\"foo\":123}";
var obj = JsonSerializer.Deserialize<HasImmutableExtensionData>(json);
Assert.IsNotNull(obj.ExtensionData);
Assert.IsTrue(obj.ExtensionData.ContainsKey("foo"));
}
}That test fails with a NullReferenceException which surprised me:
Can_deserialize_immutable_extension_data
Source: JsonExtensionDataTest.cs line 42
Duration: 39 ms
Message:
Test method JsonExtensionDataTest.JsonExtensionDataTest.Can_deserialize_immutable_extension_data threw exception:
System.NullReferenceException: Object reference not set to an instance of an object.
Stack Trace:
JsonSerializer.CreateDataExtensionProperty(JsonPropertyInfo jsonPropertyInfo, ReadStack& state)
JsonSerializer.ReadCore(JsonSerializerOptions options, Utf8JsonReader& reader, ReadStack& readStack)
JsonSerializer.ReadCore(Type returnType, JsonSerializerOptions options, Utf8JsonReader& reader)
JsonSerializer.Deserialize(String json, Type returnType, JsonSerializerOptions options)
JsonSerializer.Deserialize[TValue](String json, JsonSerializerOptions options)
JsonExtensionDataTest.Can_deserialize_immutable_extension_data() line 45
I consider the experienced behavior a bug. Another exception should have been thrown.
I would also like to request future support for using ImmutableDictionary<TKey, TValue> as backer for [JsonExtensionData].
Metadata
Metadata
Assignees
Labels
area-System.Text.Jsonbuggood first issueIssue should be easy to implement, good for first-time contributorshelp wanted[up-for-grabs] Good issue for external contributors
Activity
mwikstrom commentedon Feb 16, 2020
I believe
area-System.Text.Jsonis more appropriate for this issueahsonkhan commentedon Feb 19, 2020
cc @maryamariyan regarding bot labeling
ahsonkhan commentedon Feb 21, 2020
Similar issue to #31645 (which is a feature request).
However, in this case, there is a bug where we are getting NRE, rather than NotSupportedException.
cc @layomia
layomia commentedon Feb 21, 2020
Moving the ImmutableDictionary-as-JsonExtensionData request to #31645, and updating this issue to address the null ref.
[-]Immutable dictionary for [JsonExtensionData][/-][+]NRE when using Immutable dictionary for [JsonExtensionData][/+]