Skip to main content

Notifications

Announcements

No record found.

Dynamics 365 general forum
Unanswered

Keep order of attributes of a X++ class when serializing it to XML

Posted on by 15

Hi guys

I would like to serialize a X++ - class to XML in F&O

Here is my code snippet:

pObjectOrder is my X++ - Class using DataContract and DatatMemberAttribute

// -----

str serializedJSON = FormJsonSerializer::serializeClass( pObjectOrder );

var node = Newtonsoft.Json.JsonConvert::DeserializeXNode(serializedJSON, @"AUFTRAG");
str retXML = '<?xml version="1.0"?>' + node.ToString();

// -----

I did not find out to serialize it directly to XML, so I did use serialize it to JSON and then deserialize it to XML.

After serializing the object to JSON, I get the attributes already ordered by name and finally the same in the XML. But my customer expect the order of attributes in the XML like they were defined in the class.

Is there any way to keep th order in the XML or a way to serialize it directly into an XML instead of JSON first?

Under review

Thank you for your reply! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.

Helpful resources

Quick Links

Anton Venter – Community Spotlight

Kudos to our October Community Star of the month!

Announcing Our 2024 Season 2 Super Users!

A new season of Super Users has arrived, and we are so grateful for the daily…

Dynamics 365 Community Newsletter - September 2024

Check out the latest community news

Leaderboard

#1
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 290,552 Super User 2024 Season 2

#2
Martin Dráb Profile Picture

Martin Dráb 228,552 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,148

Leaderboard

Featured topics

Product updates

Dynamics 365 release plans