-
Notifications
You must be signed in to change notification settings - Fork 10.3k
Json serialization on RegisteredFunction.Invoke includes members with null value #16144
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
Comments
But then, if any library/component (Javascript/TypeScript) rely on the property existence if doing Interop, removing the property because it is null will return a undefined property, no ? I think JsonUtil mimick C# consistency about objects. Maybe an overload on Serialize would be a solution for this kind of scenario you are having, totally valid when calling a web api or something like that. |
Yes, it's a tricky one. But the usual behavior in web world is to ignore the null properties if I'm not mistaken. Having an option somewhere would be the best way to solve it. |
We're trying to keep |
@SteveSandersonMS Is there a way to substitute the json serialization easily? Possibly per method call. |
Actually, JsonUtil juste use SimpleJson library. You may try to call SimpleJson directly from your code, and seeing if it fulfill your requirement in any of his option. Or use Newtonsoft Json.Net if you are able (but maybe overkill). But SimpleJson seem to be present, as seeing from the JsonUtil source code. |
@Daddoon Yes, I know that. But I'd be nice to just switch the serialization provider instead of manually doing it. |
Could we introduce an interface |
@zbecknell Yep. |
Any design we come up with has to work correctly when composing together multiple third-party packages. So we can't have Proposal: we could add an extra overload to public static TRes Invoke<TRes>(string identifier, string argsArrayJson) This will allow you to do your own JSON serialization using whatever library or conventions you want and have it passed through JS interop in the same way. To make usage simpler, you can easily write your own static utility method like: public static TRes MyAppInvoke<TRes>(string identifier, params object[] args)
{
var argsJson = DoMyCustomJsonSerialization(args);
return RegisteredFunction.Invoke<TRes>(identifier, argsJson);
} Would that cover your requirements? |
@SteveSandersonMS You are right on DI - that wouldn't be good. Perhaps both options could be added. |
If I'm not mistaken, I think that serializer includes members having a null value, so if I have a type
and I serialize new Tubo(), I'd get
{ Text: null }
instead of
{}
This is a problem when you don't want to pass properties around.
The text was updated successfully, but these errors were encountered: