✅ Configure Xml Serialization
Hey folks! I have a type like this:
I'm serializing this via System.Xml. I would like to have this type serialize as if I were serializing the wrapped
Value
, rather than the whole type.
In other words, I want it to serialize as this:
rather than
What are my options to make this happen? I would ideally like to avoid changing the serializer itself, but rather use an approach that the serializer will respect. For example, newtonsoft json uses JsonConverter
, but I'm not sure if System.Xml has a similar concept.6 Replies
Unknown User•16mo ago
Message Not Public
Sign In & Join Server To View
Giving it a try now
Unknown User•16mo ago
Message Not Public
Sign In & Join Server To View
Yeah I'm hoping so. The only reason it wouldn't is because I simplified this down from the actual case, which is much more convoluted.
Looks like it's halfway there. I didn't realize that it would also add
<DateTimeWrapper>...</DateTimeWrapper>
to the serialization
Actually maybe that's fine, one sec
So here's what I'm testing:
I want the wrappers to produce the exact same xml as the built ins
Here's what I'm getting:
Everything is working except for the array element names
I would ideally not like to control this on the consuming fields, but on the type itself
XmlRoot didn't affect the element root names, unfortunatelyUnknown User•16mo ago
Message Not Public
Sign In & Join Server To View
Wonderful, thanks! I'll give it a go monday. Fairly confident this is the last piece of the puzzle so I'll close.