-
Notifications
You must be signed in to change notification settings - Fork 4.9k
New issue
Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? # to your account
JSON source gen doesn't detect [JsonNumberHandling] when applied to POCO #58638
Comments
Tagging subscribers to this area: @eiriktsarpalis, @layomia Issue DetailsThe attribute is ignored, causing number-based properties to be written as integers, for example, instead of a string. Repro: using System.Text.Json;
using System.Text.Json.Serialization;
Console.WriteLine(JsonSerializer.Serialize(new MyPOCO(), MyContext.Default.MyPOCO));
[JsonSerializable(typeof(MyPOCO))]
public partial class MyContext : JsonSerializerContext { }
[JsonNumberHandling(JsonNumberHandling.WriteAsString)]
public class MyPOCO
{
public int Id { get; set; }
} Outputs Also when applying
|
The issue can be worked around by applying the attribute on the property level. As such I don't believe it meets the bar for a 6.0.0 fix. cc @ericstj |
The attribute is ignored, causing number-based properties to be written as integers, for example, instead of a string.
Repro:
Outputs
{"Id":0}
instead of the expected{"Id":"0"}
Also when applying
[JsonSourceGenerationOptions(GenerationMode =JsonSourceGenerationMode.Serialization)]
to the context, a compile-time (or run-time based on current expected behavior) should occur since fast-path doesn't support number handling.The text was updated successfully, but these errors were encountered: