JamesNK / Newtonsoft.Json

Json.NET is a popular high-performance JSON framework for .NET
https://www.newtonsoft.com/json
MIT License
10.79k stars 3.26k forks source link

Force JsonConvert.SerializeXmlNode to serialize node value as an Integer or a Boolean #1651

Open crigiroac opened 6 years ago

crigiroac commented 6 years ago

Please tell me how we can use the attribute "json: Type = 'Integer'"? to get a serialization from xml to json with the specific data type.

I found a solution presented for the handling of data types in an alternate release in the following link

https://stackoverflow.com/questions/18611139/force-jsonconvert-serializexmlnode-to-serialize-node-value-as-an-integer-or-a-bo?rq=1

Example

string xml = @"< root xmlns:json='http://james.newtonking.com/projects/json'> <edad json:Type='Integer' @>27 "; XmlDocument doc = new XmlDocument(); doc = new XmlDocument(); doc.LoadXml(xml); string json = Newtonsoft.Json.JsonConvert.SerializeXmlNode(doc);

result : {"root":{"edad":"27"}}

expected result {"root":{"edad":27}}

crigiroac commented 6 years ago

Example

string xml = @"< root xmlns:json='http://james.newtonking.com/projects/json'> <edad json:Type='Integer' @>27 "; XmlDocument doc = new XmlDocument(); doc = new XmlDocument(); doc.LoadXml(xml); string json = Newtonsoft.Json.JsonConvert.SerializeXmlNode(doc);

result : {"root":{"edad":"27"}}

expected result {"root":{"edad":27}}

emo87 commented 6 years ago

I have same problem with boolean type. Will there be future updates on this issue? My team use Biztalk and can't use object model.

aryanf commented 3 years ago

+1

AdamsLT commented 3 years ago

Hi, has there been any discussion about this on a separate issue somewhere at all? I'd totally be interested in seeing this for my project!

All internal data transfers are in XML, transformations with XSLT and constant conversions to/from JSON, lots of third party APIs, most of the time this isn't an issue but some APIs have issues with JSON data that is all strings. Writing out classes isn't feasible for everything so for now I rely on a homebrewed solution but it isn't perfect and quite annoying to implement, so a proper one would be incredibly awesome!

This fork is a solution, if I'm not mistaken, as per the StackOverflow link posted in the OP. Seems to be only a handful of changes to get this working, so would be nice seeing this brought over. Any thoughts on this?

modrallm commented 2 years ago

+1

Also think this is a great idea to merge to the main line

frankwenner commented 8 months ago

++ Any updates here? Can someone please push this?