Support of composite JSON Schemas Draft 7

JSON Schema includes a few keywords for combining schemas together.

The keywords used to combine schemas are:

  • allOf
  • anyOf
  • oneOf

xsd2code++ support composite schemas since version 5.2. 

Support of BSON serialization

This new release allows to serialize classes in BSON format. The name "BSON" is based on the term JSON and stands for "Binary JSON". BSON originated in 2009 at MongoDb. Several scalar data types are of specific interest to MongoDB and the format is used both as a data storage and network transfer format for the MongoDB database, but it can be used independently outside of MongoDB.

To enable serialization in BSon format just select the default serializer : BSonSerializer

release 5.1.85 BSON serialization

New JSON serialization parameters

Allows to use the most useful parameters for JSON/BSON serialization. Such as : DateFormatHandedling, DateFormatString, DateParseHandedling, DateTimeZoneHandling, DefaultValueHandling, FloatFormatHandling, FloatParseHandling, MissingMemberHandling, NullValueHandling, StringEscapeHandling.

More details here : JSon Serialization

Allow to convert JSON file to JSON Schema

It is possible since this release to transform a JSON data stream into a JSON schema. This function is directly accessible from the Visual Studio solution explorer.

xsd2code json to json schema

Displays conversion errors during XSD > JSON transformation

In case of an error on the conversion of an XSD schema to JSON schema, a message specifies the origin of the error. This may be due to an XSD schema containing errors, for example.

xsd2code convertion error

Allow to Specify a "schemaLocation" for the XML file output

Until this release it was not possible to specify the schemaLocation attribute during XML serialization. This new feature adds to your classes a property that allows you to set its value and thus to serialize it. xsi:schemaLocation is an attribute of the namespace "http://www.w3.org/2001/XMLSchema-instance" that allow you to specify the location of the W3C XML Schema that you wish to use for the validation of a document.

xsd2code specify schemalocation

Include XmlNamespaceDeclarations attribute

The XmlNamespaceDeclarationsAttribute allows you to store the prefixes, and the associated namespaces, used in an XML document. For example, one common usage of the attribute is to store XPath data. In brief, an XPath is a string that contains many namespace prefixes and local names, along with some other syntax.

xsd2code XmlNamespaceDeclarations

Without the XmlNamespaceDeclarationsAttribute, the association between the prefix and the namespace is lost. To retain the association between the prefix and the namespace URI, xsd2code++ adds a property xmlns that returns an XmlSerializerNamespaces object and apply the XmlNamespaceDeclarationsAttribute attribute to the member, as shown in the following C# code:

[XmlNamespaceDeclarations()]
public XmlSerializerNamespaces xmlns;


The XmlNamespaceDeclarations attribute can only be applied once in a class to a field or property that returns an XmlSerializerNamespaces object.

Support HashSet<T> collection

In C# programming, collections like ArrayList, List, simply adds values in it without checking any duplication. To avoid such a duplicate data store, .NET provides a collection name set. This is a collection type with distinct items.

Here are some salient features of HashSet.

  • This class represent a set of values.
  • This class provides high-performance set of operations.
  • This is a set of collection that contains no duplicate elements and there is no specific order for the elements stored in it.
  • In the .NET Framework 4.6 release, the HashSet implements IReadOnlyCollection interface along with the ISet interface.
  • The HashSet class does not have any maximum capacity for the number of elements stored in it. This capacity keeps increasing as the number of elements are added in it.

Therefore, if you want to integrate collections that will automatically avoid duplication. Using HashSet is a good solution.


The use of HashSet<T> only makes sense for simple types, such as string, int, etc. For complex objects that occupy a different position in memory, you will need to implement the IEqualityComparer interface in your class.

Let's see the result of a deserialization/serialization when data from the collection is duplicated in XML data,

PurchaseOrderType po = new PurchaseOrderType();
po.ShipTo.Add("21 road street");
po.ShipTo.Add("21 road street");
var firstSerialization = po.Serialize();

The XML stream will have only one value :

<?xml version="1.0" encoding="utf-8"?>
<PurchaseOrder>
	<ShipTo>21 road street</ShipTo>
</PurchaseOrder>

Do not to overwrite .cs or .vb source files if they are read only.

En mode ligne de commande, ce paramètre permet de ne pas remplacer les fichiers cs ou vb qui sont en lecture seule. 

This option is only available on the command line. /kro (KeepReadOnly)

New JSon persistence format for code generation parameters.

This new version saves the code generation parameters in JSon format in the header of the generated files. This allows a better reading of the parameters and eliminates the default values. 

// ------------------------------------------------------------------------------
//  <auto-generated>
//    Generated by Xsd2Code++. Version 5.2.0.0. www.xsd2code.com
//    {"NameSpace":"ConsoleDotNetCoreSample","XmlAttribute":{"Enabled":true},"Serialization":{"Enabled":true}}
//  </auto-generated>
// ------------------------------------------------------------------------------
#pragma warning disable
namespace ConsoleDotNetCoreSample


Fixes and Improvements

  • Fix : JSON number type are ignored and not generated in code
  • Fix : JSON to XSD conversion should not generate nimoccurs/maxoccurs on root element
  • Fix : JSON to JSON Schema can't be cancelled on very large file
  • Fix: JSON Allows to parse JSON schemas imported from an external file
  • Fix: JSON Allows to parse JSON schemas imported from an external URL
  • Fix : Generate nullable if json type as composite type with null Like "type": ["integer", "null"]
  • Fix : Xsd2codeCustomTool no longer works.
  • Fix : Order in the parameters of the XmlElementAttribute is absent