Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

JsonSerializer does not support parsing Dictionary<TKey, TValue> #28959

Closed
pranavkm opened this issue Mar 13, 2019 · 4 comments
Closed

JsonSerializer does not support parsing Dictionary<TKey, TValue> #28959

pranavkm opened this issue Mar 13, 2019 · 4 comments
Assignees
Labels
area-System.Text.Json blocking Marks issues that we want to fast track in order to unblock other important work
Milestone

Comments

@pranavkm
Copy link
Contributor

Runtime version: 3.0.0-preview4-27513-05

Consider:

var content = "{ \"key\": \"value\" }";
var result = JsonSerializer.Parse(content, typeof(Dictionary<string, string>));

This results in the following exception:

Unhandled Exception: System.NullReferenceException: Object reference not set to an instance of an object.
   at System.Text.Json.Serialization.JsonSerializer.HandleStartObject(JsonSerializerOptions options, ReadStack& state)
   at System.Text.Json.Serialization.JsonSerializer.ReadCore(JsonSerializerOptions options, Utf8JsonReader& reader, ReadStack& state)
   at System.Text.Json.Serialization.JsonSerializer.ReadCore(Type returnType, JsonSerializerOptions options, Utf8JsonReader& reader)
   at System.Text.Json.Serialization.JsonSerializer.ParseCore(String json, Type returnType, JsonSerializerOptions options)
   at System.Text.Json.Serialization.JsonSerializer.Parse(String json, Type returnType, JsonSerializerOptions options)
@ahsonkhan
Copy link
Member

ahsonkhan commented Mar 13, 2019

Dictionary is not currently supported with the WIP JsonSerializer. See https://github.com/dotnet/corefx/issues/34372

@analogrelay
Copy link
Contributor

For the initial version to unblock ASP.NET, Dictionary<string, [some concrete type]> is sufficient.

@layomia layomia assigned layomia and unassigned steveharter Apr 16, 2019
@layomia
Copy link
Contributor

layomia commented Apr 18, 2019

Working on this now.

steveharter referenced this issue in steveharter/dotnet_corefx Apr 21, 2019
This partially addresses https://github.com/dotnet/corefx/issues/36024.
For the intial version, only `Dictionary<string, [some concrete type]>`
is supported.
layomia referenced this issue in dotnet/corefx Apr 21, 2019
* Add Dictionary support to JsonSerializer

This partially addresses https://github.com/dotnet/corefx/issues/36024.
For the intial version, only `Dictionary<string, [some concrete type]>`
is supported.

* Refactor

* Add more tests
@layomia
Copy link
Contributor

layomia commented Apr 21, 2019

We have added support for primitives: Dictionary<string, TPrimitiveType>.
It also includes support for IDictionary<string, TPrimitiveType> and IReadOnlyDictionary<string, TPrimitiveType> where an instance of Dictionary<string, TPrimitiveType> is created.

Support for non-primitives is being tracked here: https://github.com/dotnet/corefx/issues/37077.

@layomia layomia closed this as completed Apr 21, 2019
@msftgits msftgits transferred this issue from dotnet/corefx Feb 1, 2020
@msftgits msftgits added this to the 3.0 milestone Feb 1, 2020
dougbu added a commit to dotnet/aspnetcore that referenced this issue Aug 25, 2020
dougbu added a commit to dotnet/aspnetcore that referenced this issue Aug 30, 2020
dougbu added a commit to dotnet/aspnetcore that referenced this issue Sep 7, 2020
dougbu added a commit to dotnet/aspnetcore that referenced this issue Sep 9, 2020
@ghost ghost locked as resolved and limited conversation to collaborators Dec 13, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
area-System.Text.Json blocking Marks issues that we want to fast track in order to unblock other important work
Projects
None yet
Development

No branches or pull requests

6 participants