Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

XmlDataContractSerializer middleware fails for Dictionary<string, object> #7

Open
Khungersumit opened this issue Oct 4, 2022 · 1 comment

Comments

@Khungersumit
Copy link

Khungersumit commented Oct 4, 2022

Lesson 34. Demo - Implementing HATEOAS Support After POSTing)
Issue : change Accept Media type to application/xml

AddXmlDataContractSerializerFormatters middleware fails while serializing generated response for Dictionary<string, object>

In our case when we add links to Dictionary<string, object> for media-type *Accept: application/xml.

here are my dictionary's keys and values

Key1            value1
someKey1     someValue
key2             value2
someKey2     ICollection<TSource>

Serialization of this dictionarty response fails for media-type *Accept: application/xml.

@KevinDockx
Copy link
Owner

Afaik that type of serialization isn't supported out of the box by the XmlDataContractSerializer. To enable support, you can mark the the class you want to serialize with DataContract, and the members (including the dictionary) with DataMember. However, I believe that still might fail when the object isn't a simple type like string or int. If that's the case, creating a custom dictionary class that implements IXmlSerializable should do the trick! :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants