Serialising containers in X++

A problem I’ve hit a few times during troubleshooting is transferring containers from one environment to another. Importing a whole 100GB database to be able to access the results of a report packed into a 20MB container seems like a bit of an overkill. So, a natural idea would be to save the container to a file and then export. It turns out it’s not that easy, as I couldn’t find any built-in method for serialising a container to TXT or XML and saving to a file. As such, I’ve done what any developer eager to get his/her hands dirty would do and started writing my own code.

The result is added here: ExportContainerToFile

How this works is it takes a container such as the one below:

container

 

It then saves this container to a text file:

exported

 

 

 

 

 

 

 

 

 

 

In the exported file, each container contains either values or container references (e.g. “Cont#104”).

Obviously, another hard part is to de-serialise the file into a container, as all container references need to be resolved.

This is in no way a complete solution but can be seen as a starting point for future development. Some types may not de-serialise well and some new-line characters in strings may not be preserved fully. But future bug fixing should be straightforward with the core mechanism in place.

If you find any issues or have fix ideas, please do use the Comment section.

 

Disclaimer: Sample Code is provided for the purpose of illustration only and is not intended to be used in a production environment. THIS SAMPLE CODE AND ANY RELATED INFORMATION ARE PROVIDED “AS IS” WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE IMPLIED WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A PARTICULAR PURPOSE. We grant You a nonexclusive, royalty-free right to use and modify the Sample Code and to reproduce and distribute the object code form of the Sample Code, provided that. You agree: (i) to not use Our name, logo, or trademarks to market Your software product in which the Sample Code is embedded; (ii) to include a valid copyright notice on Your software product in which the Sample Code is embedded; and (iii) to indemnify, hold harmless, and defend Us and Our suppliers from and against any claims or lawsuits, including attorneys’ fees, that arise or result from the use or distribution of the Sample Code