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
JObject.FromObject(x) acts as a "shortcut" to JObject.Parse(JsonConvert.SerializeObject(x)). If it doesn't act like such a shortcut by default, a flag could be passed to the serializer for JObject.FromObject to enable behaviour that makes it a shortcut to serializing to string, then parsing again.
Actual behavior
JObject.FromObject embeds additional metadata into the values, like JTokenType.Guid, JTokenType.Date, etc. This creates a difference in behaviour between JObject.FromObject and using JObject.Parse on a previously serialized version of the same object. This is very frustrating when having to write code that has to deal with JObject instances from both sources.
Steps to reproduce
publicrecordExample(GuidId);publicclassProgram{publicstaticvoidMain(string[]args){varexample=new Example(Guid.NewGuid());// Convert to string and parse thatvarexampleJsonFromParsedString= JObject.Parse(JsonConvert.SerializeObject(example));varexampleIdFromParsedString= exampleJsonFromParsedString.Value<string>("Id");
Console.Out.WriteLine("exampleIdFromParsedString = {0}", exampleIdFromParsedString);// Convert to JObject directlyvarexampleJsonFromObject= JObject.FromObject(example);varexampleIdFromObject= exampleJsonFromObject.Value<string>("Id");
Console.Out.WriteLine("exampleIdFromObject = {0}", exampleIdFromObject);}}
Related: #1449 (note, I am not saying those JTokenTypes should be removed, I am just asking for a way to opt-out of them when serializing directly to JObject).
The text was updated successfully, but these errors were encountered:
Source/destination types
Source/destination JSON
Expected behavior
JObject.FromObject(x)
acts as a "shortcut" toJObject.Parse(JsonConvert.SerializeObject(x))
. If it doesn't act like such a shortcut by default, a flag could be passed to the serializer forJObject.FromObject
to enable behaviour that makes it a shortcut to serializing to string, then parsing again.Actual behavior
JObject.FromObject
embeds additional metadata into the values, likeJTokenType.Guid
,JTokenType.Date
, etc. This creates a difference in behaviour betweenJObject.FromObject
and usingJObject.Parse
on a previously serialized version of the same object. This is very frustrating when having to write code that has to deal withJObject
instances from both sources.Steps to reproduce
Related: #1449 (note, I am not saying those JTokenTypes should be removed, I am just asking for a way to opt-out of them when serializing directly to JObject).
The text was updated successfully, but these errors were encountered: