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
Newtonsoft.Json allows you to pass context to its JSON serializer via serializer settings that can later be retrieved in the callbacks. This works well enough for objects that need a specific property (like parent clients, status, etc.) to be set as passed value and it works at any depth. Unfortunately, there isn't a way to do that with System.Text.Json apart from using custom converters, that can't have serializer settings to be passed down (and you can't pass the property value to child types that require same property set if settings aren't passed). This can make it harder to move certain projects over to System.Text.Json and if not make it worse in some instances.
publicclassSomeObject:IJsonOnDeserialized<int>{publicintStatus{get;set;}publicvoidIJsonOnDeserialized.OnDeserialized(SomeContextType<int>context)=>Status=context.Value;// ... Now we can set up methods or anything else with the received context ...}
Risks
This could lead to breaking changes if callback interfaces wouldn't use generic types.
This was discussed in the serialization callback API proposal, see #54528 (comment). I understand passing contexts was cut since it would be difficult to support in the current iteration of source generation.
JsonSerializer doesn't support passing user state for the moment. This is something we might consider in #71718 and will be implemented in tandem with #63795. Closing as duplicate of #71718.
Activity
eiriktsarpalis commentedon Oct 5, 2021
This was discussed in the serialization callback API proposal, see #54528 (comment). I understand passing contexts was cut since it would be difficult to support in the current iteration of source generation.
cc @steveharter
eiriktsarpalis commentedon Oct 11, 2021
This would likely need to be considered in combination with #36785.
eiriktsarpalis commentedon Jul 19, 2022
JsonSerializerdoesn't support passing user state for the moment. This is something we might consider in #71718 and will be implemented in tandem with #63795. Closing as duplicate of #71718.