function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
code developercode developer 

Xml to Apex class deserialise



We have  to deserialize json to apex class.


Similarly I need to deserialise XML to apex class.


Are there any tools like above mentioned url to deserialise xml to apex.






I could not find any tool for desealizing XML to Apex class. I would suggest you to simply make use of XMLStreamReader class to read the XML and then you can use the result, also if you want to convert XML simply to string then you can use toXmlString from Documnet class.





Shaun RipleyShaun Ripley
For anyone else coming across this forum and looking for a solution. There is a library available here:

It offers both serialization and deserialization. An example of your use case can be seen below:
Contact contact = (Contact) XML.deserialize('<Contact><attributes><type>Contact</type><url>/services/data/v48.0/sobjects/Contact/0032w000005DrR2AAK</url></attributes><FirstName>First</FirstName><LastName>Last</LastName><Id>0032w000005DrR2AAK</Id></Contact>')