RehanSaeed / Schema.NET

Schema.org objects turned into strongly typed C# POCO classes for use in .NET. All classes can be serialized into JSON/JSON-LD and XML, typically used to represent structured data in the head section of html page.
MIT License
640 stars 80 forks source link

XML Serialisation #637

Open SmithPlatts opened 11 months ago

SmithPlatts commented 11 months ago

Describe the feature

Hi;

Has anyone had any success serialising any of the POCO classes to XML? I've tried both XmlSerializer and DataContractSerializer, but they both freak out for different reasons.

Is there something simple I'm missing?

Schema objects

No response

Turnerj commented 8 months ago

Hey @SmithPlatts - haven't actually tried XML serialization before. I imagine it may have some trouble with our OneOrMany and Values types without some dedicated serializer for the,. If there are just some attributes we need to set on properties, that could be something easy enough for us to apply to the library though.

SmithPlatts commented 8 months ago

Hi @Turnerj, cheers for opening the conversation.

I was actually thinking of giving that a go in my branch, and if it works without impacting the perf of the library, was going to open a PR for your review and comment.

Turnerj commented 8 months ago

I don't imagine the existing performance of the library would be impacted - like if we just need extra attributes, that's effectively a no-op in terms of performance. If we need a new XML-based serializer, that's a bit more work and more tests to do it thoroughly. Really hoping we can get away with just some attributes etc to decorate properties!

SmithPlatts commented 8 months ago

I've encountered circumstances where even attributes can change the compiler behaviour, and introduce a regression; not common, but I'm an overly defensive developer 😂

Happy to investigate the matter, and start with attributes. If a serialiser is also required, will be adding it test-first.

I'll let you know how things go.