How to drop "exs:type" when serializing derived types
See original GitHub issueThis is not an issue but rather question for help.
I have following object structure:
class Container
{
public string Common { get; set; } = "Common";
public IBody Body { get; set; }
}
interface IBody
{
string BodyType { get; set; }
}
class A : IBody
{
public string BodyType { get; set; } = "A";
public string FieldX { get; set; } = "FieldX";
}
class B : IBody
{
public string BodyType { get; set; } = "B";
public string FieldY { get; set; } = "FieldY";
}
I serialize it with following code:
var serializer = new ConfigurationContainer()
.UseOptimizedNamespaces()
.EnableImplicitTyping(typeof(Container))
.EnableImplicitTyping(typeof(A))
.EnableImplicitTyping(typeof(B))
.EnableImplicitTyping(typeof(IBody))
.Create();
var result = serializer.Serialize(new XmlWriterSettings { OmitXmlDeclaration = true}, container);
And I get this as result
<Container xmlns:exs="https://extendedxmlserializer.github.io/v2" xmlns="clr-namespace:Namespace.Test;assembly=Test"><Common>Common</Common><Body exs:type="A"><BodyType>A</BodyType><FieldX>FieldX</FieldX></Body></Container>
Is there any way to get rid of exs:type
and rest of namespace related attributes somehow? I am only interested in serialization.
My receiving party is a custom XML parser and it has problems with namespace parsing…
Issue Analytics
- State:
- Created 3 years ago
- Comments:7 (4 by maintainers)
Top Results From Across the Web
How to serialize properties of derived classes with System. ...
In this article. Serialize properties of derived classes; Polymorphic type discriminators; Configure polymorphism with the contract model ...
Read more >c# - Json.net serialize/deserialize derived types?
The issue is I have a list which contains both base and derived objects. So I need to figure out how I tell...
Read more >Serialization of derived data types
One option is to go into details of what is actually necessary to write down for every single object. This will work but...
Read more >Inheritance - cereal Docs
This page is concerned with how to serialize base classes from a derived class. Another important and related feature of inheritance, polymorphism, is...
Read more >Skip serializing field
Please use the skip attribute to skip both serializing and deserializing (see Field Attributes: skip ). Likewise, use skip_deserializing to skip deserializing ......
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
Issue-Label Bot is automatically applying the label
question
to this issue, with a confidence of 0.74. Please mark this comment with 👍 or 👎 to give our bot feedback!Links: app homepage, dashboard and code for this bot.
O thanks. It would be nice to have it but I understand. Anyway - great project.
As for my case I resorted for second best thing after XSLT - regex 😃 I will leave it for reference here for future :
BTW would you accept PR that adds option to disable namespace generation?