-
Notifications
You must be signed in to change notification settings - Fork 654
add JSON Serializer #2060
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
add JSON Serializer #2060
Conversation
@gep13 new build failure 🤔
However I am not seeing that locally |
Okay now I am just generating unexpected data:
|
I get it. This happens because we extends IEnumerable |
@asbjornu I am somewhat concerned about returning null's as it might change the behavior on too many places, it seems like a breaking change. |
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.
Should we return null or keep empty strings ""
in JSON?
Need to update tests either way.
{ | ||
// Credit to https://github.com/neuecc | ||
// Inspired by https://gist.github.com/neuecc/7d728cd99d2a1e613362 | ||
public static class JsonSerializer |
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.
Is this overkill?
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.
Hm. This turned out quite a bit more complicated than I had originally visioned, seeing how naïve the existing custom serialization code is. Is all of this necessary?
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.
I can write a simpler one that only supports dictionary in one depth?
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.
@asbjornu Please take another look, I chose a more simplified version that can only do objects.
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.
Much simpler and sufficient, I think. If we need the full power of a full-fledged JSON serializer, we'll add a dependency to one, but I don't think that need is here at the moment.
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.
The problem with adding such dependency is that you may have dependency conflicts with those using the same JSON serializer dependency.
Reason for #2017 😉 When using AppVeyor, that needed ewtonsoft.json dep and the project uses newtonsoft.json in a different version.
|
||
var stringContent = new StringContent(body, Encoding.UTF8, "application/json"); | ||
var stringContent = new StringContent(JsonSerializer.Serialize(body), Encoding.UTF8, "application/json"); |
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.
Hey, it's back using our own Serializer 🙇
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.
😄
value = kvp.Value; | ||
} | ||
|
||
public static IEnumerable<KeyValuePair<string, string>> GetProperties(this object obj) |
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.
Could properly use a better name 🤔
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.
I think GetProperties
is fine?
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.
I think this looks good! Tests are green and all is well. 😃
value = kvp.Value; | ||
} | ||
|
||
public static IEnumerable<KeyValuePair<string, string>> GetProperties(this object obj) |
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.
I think GetProperties
is fine?
{ | ||
// Credit to https://github.com/neuecc | ||
// Inspired by https://gist.github.com/neuecc/7d728cd99d2a1e613362 | ||
public static class JsonSerializer |
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.
Much simpler and sufficient, I think. If we need the full power of a full-fledged JSON serializer, we'll add a dependency to one, but I don't think that need is here at the moment.
all green @arturcic |
it's up to @asbjornu to merge, as he did the review |
Thank you so much for your contributions, @Casz! 🙏 |
Thank you for accepting my contributions @asbjornu 🙇 Just want to make it more clear why this was added, see the updated description. |
The problem with adding a JSON Serializer dependency is that you may have dependency conflicts with those using the same JSON serializer dependency.
Reason for #2017 😉 When using AppVeyor, that needed newtonsoft.json dep and the project uses newtonsoft.json in a different version will cause such a conflict.