-
-
Notifications
You must be signed in to change notification settings - Fork 568
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
Improve stringify for JObject #1009
Conversation
lahma
commented
Nov 16, 2021
•
edited
Loading
edited
- JObjectArray Stringify error #1005 (comment)
- improves property traversal of JObject fixing serialization
- still requires custom JTokenConverter in order to map Newtonsoft primitives to correct JS primitives, we just don't know how to handle them otherwise
6a4b357
to
32e9d78
Compare
if (_engine.ClrTypeConverter.TryConvert(key, typeof(string), CultureInfo.InvariantCulture, out var stringKey)) | ||
object stringKey = key as string; | ||
if (stringKey is not null | ||
|| _engine.ClrTypeConverter.TryConvert(key, typeof(string), CultureInfo.InvariantCulture, out stringKey)) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Would probably work without the custom IObjectConverter by checking for IConvertible
and ultimately for IFormattable
if we know we want a string.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That's how Fluid can handle JToken
without configuration.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Here I just wanted to create a fast path when we already have a string, but might be worth some PR to improve string coercion
@sebastienros OK to merge? |
|
Did I get it right? Cool stuff, nonetheless. |
It's better than what I do in FLuid ... I might want to do it this way too. Thanks! |
Apparently |
This version doesn't (probably) cause boxing so I guess this is a bit more optimal for these primary types. We don't need to go finding a converter on a second pass when we do this already in our own code. Can I merge or something to improve? |