- We create an xsd schema that matches a json
- generate a c# class from the xsd schema
- Use newtonsoft.json to deserialize the json to object and object to xml(based on the generated class)
This is needed as the product we use can only deal with xml and not json. This works fine for most of the json responses.
Now we have to support additional properties(any) in the incoming json. So we have created a xsd schema with an "Any" element with "ProcessContents = lax". The generated class contains the any element as shown below.
public System.Xml.XmlElement Any
{
get { return this.anyField; }
set { this.anyField = value; }
}
The following is the behaviour with different Json inputs.
- The json must contain the name "Any" to match the any element. This does not fulfil the additional properties idea.
- I could add a "JsonProperty("SomeName")" but still I should know the additional properties name which I wouldnt.
Could someone provide a way to do this please. Thanks.
Edit1:
After suggestions to use JsonExtensionData, the class looks like this.
I see that the additionalproperties are deserialized to an object as seen in the image below.
Error received : "Cannot serialize member .AdditionalProperties of type System.Collections.Generic.Dictionary`2[[System.String, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089],[System.Object, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089]], because it implements IDictionary."}
Question: How tio solve this and serialize this to XmlAny Element? Thanks.