I created an API wrapper class library for consuming a rest API from a 3rd party.
It was all working until they recently updated the API in the latest version of their product and added a namespace to the root element, now my deserialization code is failing.
An example of one of my classes:
[Serializable]
[XmlRootAttribute(ElementName = "exit_survey_list")]
public class SupportExitSurveyCollection : ApiResult { .... }
If I set the Namespace property in the XmlRootAttribute to the new namespace being returned, then it works properly again.
But I need to support both versions of the API (namespaced and not) because I cannot be sure which version of the API will be available.
I'd like to get this working without duplicating classes for different versions, but not sure if it's possible.
Thanks for any input/advice.
I don't think that is possible.
You could implement the IXmlSerializable interface, and control serialization yourself - that would work but it is probably not what you want, since it would require you to do a lot of the mapping yourself in code.
Another option would be to pre-process the messages and add the namespace if it is missing. Then you can have a single deserialization process.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With