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
Code generated by Json source generator results in warnings in projects with nullable enabled #52227
Aren't the warnings correct in this case, because System.Text.Json ignores the non-nullability?
There's robust logic in STJ to handle null on serialization and deserialization, including to support features like ignoring null on serialization. Because of this we don't leak NullReferenceException and related bugs. However, it would be most correct to accept T? on deserialization and return T? on serialization, since property values could indeed be null. Unfortunately, I couldn't find a way to express this in a prototype to have the correct semantics, due error CS0453 given this code.
In the fix for the issue #57178, I left the parameter type as Func<object, T>? getter and just banged the return value of the getter call in the generated code.
Activity
Trolldemorted commentedon Jun 22, 2021
Aren't the warnings correct in this case, because System.Text.Json ignores the non-nullability?
layomia commentedon Aug 10, 2021
There's robust logic in STJ to handle
nullon serialization and deserialization, including to support features like ignoringnullon serialization. Because of this we don't leakNullReferenceExceptionand related bugs. However, it would be most correct to acceptT?on deserialization and returnT?on serialization, since property values could indeed benull. Unfortunately, I couldn't find a way to express this in a prototype to have the correct semantics, due error CS0453 given this code.In the fix for the issue #57178, I left the parameter type as
Func<object, T>? getterand just banged the return value of the getter call in the generated code.