Skip to content
This repository has been archived by the owner on Aug 30, 2023. It is now read-only.

Convert extra when extra is not serializable #185

Merged
merged 3 commits into from
May 15, 2017
Merged

Convert extra when extra is not serializable #185

merged 3 commits into from
May 15, 2017

Conversation

skyline75489
Copy link
Contributor

This fixed #180

Copy link
Contributor

@asbjornu asbjornu left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This looks pretty good. I have a couple of comments, but otherwise I give this 👍 .

{
result = JObject.FromObject(extra);
}
catch (ArgumentException e)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No need for an instance e here, is it?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Indeed.

}
catch (ArgumentException e)
{
result = JObject.Parse(string.Format(@"{{""{0}"":""{1}""}}", extra.GetType(), extra));
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This seems a bit sub-optimal. Can't we instantiate a new JObject and give it a property somehow?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It seems the solution is either this or dynamic object. I personally do not favor any usage of dynamic, though.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Seems like this works just fine:

result = JObject.FromObject(new Dictionary<string, object>
{
    { extra.GetType().ToString(), extra }
});

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah there's Dictionary... I'm too obsessed with the dynamic type thing in JSON and forgot about it. Should it be Dictionary<string, string>, though? Or it's handled by Json.Net itself?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

JSON.NET serializes object just fine. 😃

@asbjornu asbjornu merged commit 140bdb2 into getsentry:develop May 15, 2017
@asbjornu
Copy link
Contributor

@skyline75489: Excellent work, thanks!

@skyline75489 skyline75489 deleted the fix/180 branch May 15, 2017 09:07
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Catch exception during the creation of JsonPacket
2 participants