You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Developers using System.Text.Json have their top requests addressed so that they can use STJ in more scenarios #45190
Cost:LWork that requires one engineer up to 4 weeksPriority:1Work that is critical for the release, but we could probably ship withoutUser StoryA single user-facing feature. Can be grouped under an epic.area-System.Text.JsontrackingThis issue is tracking the completion of other related issues.
changed the title [-]Miscellaneous improvements in System.Text.Json[/-][+]User Story: Developers using System.Text.Json want miscellaneous features so that they can use STJ in more scenarios[/+]on Jan 21, 2021
changed the title [-]User Story: Developers using System.Text.Json want miscellaneous features so that they can use STJ in more scenarios[/-][+]Developers using System.Text.Json have their top requests addressed so that they can use STJ in more scenarios[/+]on Jan 21, 2021
Failing null deserialization on non-nullable references types (#1256) would be awesome. Right now we have to check the entire children tree whether there was a null value, which is very annoying.
Please allow to leave "null" when serialize unsupported types.
Currently if a type is not owned by myself and it contains a ref struct property (eg. Span<T>), I have no way to serialize it to JSON because System.Text.Json will always throw a NotSupportedException. Newtonsoft.Json can just skip the unsupported properties and leave them as null.
@layomia i see my #42163 got removed but i dont see it being moved elsewhere. It got triaged out or deleted by accident? Just curious in worst case i will fork S.T.J when this lib gets all other major features that are missing from json.net
@BreyerW I was updating the related issue #40099 as done for 6.0 and noticed that #42163 is marked for "Future". I recall discussing it with @jozkee earlier - it strikes me as a niche and design-heavy problem that we might not get to in 6.0. It would be good to see more feedback from other customers to prioritize the work for the current release. My intention when adding it to this list was to remember assess to its feasibility for 6.0. At this point it seems unlikely, given the other JSON work we need to do in this release (https://themesof.net/?q=json%20is:open%20kinds:teu).
Can we continue the discussion over at #42163? The feature to deserialize into an existing object (#29538) was mentioned as a potential workaround and is more likely to make it to 6.0 given it's relative technical simplicity, precedent in Newtonsoft.Json, and demand from multiple customers.
JsonSerializer will not look for these attributes itself, but can provide APIs for users to do so and populate relevant JsonTypeInfo, JsonPropertyInfo members which will honor those options.
I know System.Text.Json won't invoke private members by default, but I'm surprised and disappointed that we cannot explicitly denote private constructors with [JsonConstructor].
Ideally I'd like to reuse the same DTO types in Newtonsoft.Json and System.Text.Json contexts (with suitable using JsonPropertyAttribute = System.Text.Json.Serialization.JsonPropertyNameAttribute in #if USE_STJ at the top of the .cs file), however my projects tend to use primary-constructors which STJ doesn't support, so I can't use the above trick just yet.
Allow [JsonConstructor] with private constructors, even when a public constructor is available.
This is essential for cases where a type has different constructors for different states, with per-state validation logic (for an example, see my class SqlDbTypeRef in the expanding region below). Exposing a public constructor that has parameters for all properties would allow consumers to unwittingly circumvent the validation rules - and requiring us to reimplementing the validation logic in this new constructor is not endearing me to use STJ over NJ.
Allow [JsonPropertyName] on constructor parameters and use JsonPropertyNameAttribute.Name to map them to C# properties' JsonPropertyNameAttribute.Name instead of their C# property names.
This make it easier to write DTOs that are more resilient to unintentional symbol renames when refactoring - especially as Visual Studio's C# Refactor-Rename tool does not currently rename constructor parameters that are assigned to POCO properties.
Allowing explicit JSON property names on ctor parameters also allows us to tweak serialization vs. deserialization logic without needing too much effort.
A use-case for this is when you want the same DTO to intentionally ignore or drop certain properties when deserializing but still serialize them and you're using code-gen or T4 to generate DTOs and having to use custom logic in the ctor is just too much effort.
This is useful when the private [JsonConstructor] is also used by a public static factory method and additional details are routed through there but would not come from JSON - so the constructor has more parameters than JSON properties.
For example, I have a class that represents a SqlDbType with length, precision, and scale parameters - this is what I currently have working with Newtonsoft.Json:
Allow [JsonPropertyName] on constructor parameters and use JsonPropertyNameAttribute.Name to map them to C# properties' JsonPropertyNameAttribute.Name instead of their C# property names.
Kindly open a new issue to track this feature request.
Triage - we can consider this work done and I'll close this issue. We've addressed what we could in the .NET 6.0 timeframe, and can consider the other tasks in .NET 7.0 planning.
Cost:LWork that requires one engineer up to 4 weeksPriority:1Work that is critical for the release, but we could probably ship withoutUser StoryA single user-facing feature. Can be grouped under an epic.area-System.Text.JsontrackingThis issue is tracking the completion of other related issues.
Activity
MhAllan commentedon Dec 1, 2020
JsonSerializer TimeSpan support - is very important, everyone run back to Newtonsoft because of this.
Romfos commentedon Dec 23, 2020
Allow support for non-public members +++++
ishepherd commentedon Jan 5, 2021
Can any of these be plugged in naturally by a 3rd party if they had the right extensibility support?
A 3rd party library can evolve so much easier than .NET
[-]Miscellaneous improvements in System.Text.Json[/-][+]User Story: Developers using System.Text.Json want miscellaneous features so that they can use STJ in more scenarios[/+][-]User Story: Developers using System.Text.Json want miscellaneous features so that they can use STJ in more scenarios[/-][+]Developers using System.Text.Json have their top requests addressed so that they can use STJ in more scenarios[/+]Trolldemorted commentedon Jan 23, 2021
Failing null deserialization on non-nullable references types (#1256) would be awesome. Right now we have to check the entire children tree whether there was a null value, which is very annoying.
hez2010 commentedon Feb 24, 2021
Please allow to leave "null" when serialize unsupported types.
Currently if a type is not owned by myself and it contains a
ref structproperty (eg.Span<T>), I have no way to serialize it to JSON becauseSystem.Text.Jsonwill always throw aNotSupportedException.Newtonsoft.Jsoncan just skip the unsupported properties and leave them as null.dan655t commentedon Mar 8, 2021
Would also like to see full emoji support (#42847). Without it we're unable to use
System.Text.Jsonfor user generated content.Edit: this can be disregarded. I have closed (#42847).
BreyerW commentedon Apr 21, 2021
@layomia i see my #42163 got removed but i dont see it being moved elsewhere. It got triaged out or deleted by accident? Just curious in worst case i will fork
S.T.Jwhen this lib gets all other major features that are missing from json.netlayomia commentedon Apr 21, 2021
@BreyerW I was updating the related issue #40099 as done for 6.0 and noticed that #42163 is marked for "Future". I recall discussing it with @jozkee earlier - it strikes me as a niche and design-heavy problem that we might not get to in 6.0. It would be good to see more feedback from other customers to prioritize the work for the current release. My intention when adding it to this list was to remember assess to its feasibility for 6.0. At this point it seems unlikely, given the other JSON work we need to do in this release (https://themesof.net/?q=json%20is:open%20kinds:teu).
Can we continue the discussion over at #42163? The feature to deserialize into an existing object (#29538) was mentioned as a potential workaround and is more likely to make it to 6.0 given it's relative technical simplicity, precedent in Newtonsoft.Json, and demand from multiple customers.
MuleaneEve commentedon May 27, 2021
Please, also add support for the new DateOnly and TimeOnly structs.
Edit: Otherwise, they will be avoided in any scenario that also uses STJ.
layomia commentedon Jun 1, 2021
I updated the work items:
Added
Moved to "More extensible object and collection converters" #36785
JsonSerializerwill not look for these attributes itself, but can provide APIs for users to do so and populate relevantJsonTypeInfo,JsonPropertyInfomembers which will honor those options.Moved to future
These are good features but can be addressed later given other work we need to do for this release.
daiplusplus commentedon Jul 22, 2021
I know
System.Text.Jsonwon't invokeprivatemembers by default, but I'm surprised and disappointed that we cannot explicitly denote private constructors with[JsonConstructor].Ideally I'd like to reuse the same DTO types in
Newtonsoft.JsonandSystem.Text.Jsoncontexts (with suitableusing JsonPropertyAttribute = System.Text.Json.Serialization.JsonPropertyNameAttributein#if USE_STJat the top of the.csfile), however my projects tend to use primary-constructors which STJ doesn't support, so I can't use the above trick just yet.[JsonConstructor]withprivateconstructors, even when apublicconstructor is available.class SqlDbTypeRefin the expanding region below). Exposing apublicconstructor that has parameters for all properties would allow consumers to unwittingly circumvent the validation rules - and requiring us to reimplementing the validation logic in this new constructor is not endearing me to use STJ over NJ.[JsonPropertyName]on constructor parameters and useJsonPropertyNameAttribute.Nameto map them to C# properties'JsonPropertyNameAttribute.Nameinstead of their C# property names.[JsonConstructor]parameter-to-property mapping.[JsonConstructor]is also used by apublic staticfactory method and additional details are routed through there but would not come from JSON - so the constructor has more parameters than JSON properties.For example, I have a class that represents a
SqlDbTypewithlength,precision, andscaleparameters - this is what I currently have working withNewtonsoft.Json:Click to expand!
layomia commentedon Jul 23, 2021
@Jehoel
This is tracked by #31511.
Kindly open a new issue to track this feature request.
This is generally tracked by #44428. Please add a note on that issue describing the sort of functionality enhancements you'd like to see.
layomia commentedon Jul 23, 2021
Triage - we can consider this work done and I'll close this issue. We've addressed what we could in the .NET 6.0 timeframe, and can consider the other tasks in .NET 7.0 planning.