The code generated for Serializer/Deserializer uses JSon.Net from NewtonSoft. Detailed documentation is available on the official website https://www.newtonsoft.com/.
xsd2code++ allows to configure the serializer on the setting that is the most relevant. Those can evolve over time with the addition of additional parameters. These parameters are detailed after this document.
How to enable JSON serialization?
The first thing to do is to enable the generation of serialization methods like this :
Serialization→Enable = true
Serialization→DefaultSerialiser = JSonSerializer
This is enough to produce a JSON file or stream from the generated classes. Chacune de vos classes contiendra les méthode de serialization & deserialisation. Toutefois, il est possible de regrouper le tout dans une classe de base. Pour cela l'option ci-dessous doit être activé
GenericBaseClass → Enable = true
#region Serialize/Deserialize /// <summary> /// Serializes current PurchaseOrderType object into an json string /// </summary> public virtual string Serialize() { Newtonsoft.Json.JsonSerializerSettings settings = new Newtonsoft.Json.JsonSerializerSettings(); return JsonConvert.SerializeObject(this, settings); } /// <summary> /// Deserializes PurchaseOrderType object /// </summary> /// <param name="input">string workflow markup to deserialize</param> /// <param name="obj">Output PurchaseOrderType object</param> /// <param name="exception">output Exception value if deserialize failed</param> /// <returns>true if this Serializer can deserialize the object; otherwise, false</returns> public static bool Deserialize(string input, out PurchaseOrderType obj, out System.Exception exception) { exception = null; obj = default(PurchaseOrderType); try { obj = Deserialize(input); return true; } catch (System.Exception ex) { exception = ex; return false; } } public static bool Deserialize(string input, out PurchaseOrderType obj) { System.Exception exception = null; return Deserialize(input, out obj, out exception); } public static PurchaseOrderType Deserialize(string input) { Newtonsoft.Json.JsonSerializerSettings settings = new Newtonsoft.Json.JsonSerializerSettings(); return JsonConvert.DeserializeObject<PurchaseOrderType>(input, settings); } #endregion public virtual void SaveToFile(string fileName) { System.IO.StreamWriter streamWriter = null; try { string xmlString = Serialize(); System.IO.FileInfo outputFile = new System.IO.FileInfo(fileName); streamWriter = outputFile.CreateText(); streamWriter.WriteLine(xmlString); streamWriter.Close(); } finally { if ((streamWriter != null)) { streamWriter.Dispose(); } } } public static PurchaseOrderType LoadFromFile(string fileName) { System.IO.FileStream file = null; System.IO.StreamReader sr = null; try { file = new System.IO.FileStream(fileName, FileMode.Open, FileAccess.Read); sr = new System.IO.StreamReader(file); string xmlString = sr.ReadToEnd(); sr.Close(); file.Close(); return Deserialize(xmlString); } finally { if ((file != null)) { file.Dispose(); } if ((sr != null)) { sr.Dispose(); } } } }