A quickstart to Xsd2Code

Ferbuary 2021

Once you've successfully installed xsd2Code all you have to do is put you Json schema into the project in Visual Studio from there all you have to do is right click the file and you should see an xsd2Code option in the menu

Tooltip that appears when you rightclick on the Json schema while Xsd2Code is installed

Once the tool starts running you will see a preview of what your generated class will look like, if anything bothers you in it, do not fret you have quite a large number of options on the left of the screen

The options page with settings on the Left-side and a preview of the generated code on the right-sight

For example, personnally I prefer my gets and sets in the simple automatic way this can be changed like many other things on the left side of your screen. In my case the property I need to change is nested in the Output property settings' Properties, what we're looking for is the Automatic properties setting that should be on False.

Shows the path to take to get to the AutomaticProperties

Once you put this setting on True you should see the program regenerate your class with the appropriate changes, in our example it should now look like this.

The properties with the Automatic getters and setters

Instead of

The properties with the manual style of getters and setters


You can check out our other articles to see what can be done with the other settings, but for now let's move on.

Once you're satisfied with your options, you can continue by clicking generate at the bottom right corner 

Once your class is generated, you're ready to go, have fun 

But if you're willing to stay a bit longer I can show you how to make use of some of the functions this tool can generate for you to write and read json files.  

Serialization

By default the generation of these functions is turned off, to turn them on you need to look for the Serialization option in the Output advanced code settings.

The properties section that lead to turning the options to enable serialization

Make sure to have the proper filetype selected in the DefaultSerializer in our case it's Json, make sure it is all Enabled in the Enabled setting.

(If you see errors relating to NewtonSoft don't worry we'll get to it)

Once the settings are set and you press generate your class or classes should have a couple of new functions : 

-SaveToFile         xsd2code serialization SaveToFile


-LoadFromFile    Shows the LoadFromFile function


-Serialize           xsd2code serialization


-Deserialize       xsd2code deserialize

You won't need to interact with the serialization part of the code unless you know what you're doing

Assuming you're working with single objects and not a list of them (An array would be better) when you use the Customers' (in our case) SaveToFile property with a valid path argument it will write that instance of the object into the file after serializing into the right format. The same thing but in the opposite direction happens when you LoadFromFile

But you might've seen errors in the class, that comes from the fact that you probably haven't installed Newtonsoft, it's because these functions use the Newtonsoft Json.Net : https://www.newtonsoft.com/json

You need to add the NuGet of Newtonsoft.Json, once you did that everything should work fine.

Thank you for using our product, if you want to learn check out our other articles on the things you can do with XSD2Code

Terms & privacy

Terms of uses · Privacy policy 

Contact

CodeNGine Technologies, 19 Avenue, de la gare, 34770 Gigean, France. SIRET: 85257252800010, VAT : FR 62852572528
codengine.technologies@xsd2code.com

About the company

CodeNGine Technologies is software company based in the South of France that provides an advanced productivity code generation tool to developers using XML and JSON


Copyright © 2021 CodeNGine Technologies