-
Notifications
You must be signed in to change notification settings - Fork 4.9k
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
JSON deserialization for positional record throws exception w/ Source Generator #56182
Comments
Tagging subscribers to this area: @eiriktsarpalis, @layomia Issue DetailsDescriptionFollowing the instructions here: https://devblogs.microsoft.com/dotnet/try-the-new-system-text-json-source-generator/ I created a new project, installed the latest build for the System.Text.Json package:
Code: internal record Person(string FirstName, string LastName);
[JsonSourceGenerationOptions(
PropertyNamingPolicy = JsonKnownNamingPolicy.CamelCase)]
[JsonSerializable(typeof(Person))]
internal partial class MyJsonContext : JsonSerializerContext
{
}
Person person = new(FirstName: "Jane", LastName: "Doe");
byte[] utf8Json = JsonSerializer.SerializeToUtf8Bytes(person, MyJsonContext.Default.Person);
person = JsonSerializer.Deserialize<Person>(utf8Json); // works
person = JsonSerializer.Deserialize<Person>(utf8Json, MyJsonContext.Default.Person); // fails This works when using the reflection based deserialization. But throws a NotSupportedException: "Deserialization of types without a parameterless constructor, a singular parameterized constructor, or a parameterized constructor annotated with 'JsonConstructorAttribute' is not supported." although the record only has a single parameterized constructor, AFAIK. Configuration
Regression?no. Other information
|
Thanks for the feedback! I'm currently working on a PR fixing this and will tag you once it's ready. |
Description
Following the instructions here: https://devblogs.microsoft.com/dotnet/try-the-new-system-text-json-source-generator/ I created a new project, installed the latest build for the System.Text.Json package:
dotnet new console
dotnet add package System.Text.Json --version 6.0.0-rc.1.21372.4
Code:
This works when using the reflection based deserialization.
But throws a NotSupportedException: "Deserialization of types without a parameterless constructor, a singular parameterized constructor, or a parameterized constructor annotated with 'JsonConstructorAttribute' is not supported." although the record only has a single parameterized constructor, AFAIK.
Configuration
Regression?
no.
Other information
The text was updated successfully, but these errors were encountered: