I want to control the output of the root node when returning IEnumerable<T>. Currently, I get an <ArrayOf_> node as the root:
<ArrayOfMyClass xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
<MyClass>
<Number>1</Number>
</MyClass>
<MyClass>
<Number>2</Number>
</MyClass>
</ArrayOfMyClass>
I want to be able to change this to something else (and for that matter, without a namespace):
<NewRoot>
<MyClass>
<Number>1</Number>
</MyClass>
<MyClass>
<Number>2</Number>
</MyClass>
</NewRoot>
I don’t want to create a group class, because although this would work for XML, I don’t want the group class collection property in my JSON output:
{
"ListOfMyClass": [
{
"Number": 1
},
{
"Number": 2
}
]
}
Instead I want to keep it as it would be by default:
[
{
"Number": 1
},
{
"Number": 2
}
]
I realise there are a few similar questions that have appear to have been answered but all them lead me to a dead end. I could also hack the result myself (yuck), but I’m hoping there is a best-practice way to do this with the stuff provided; annotations, formatters etc.
Has anyone had any success with this whilst leaving the JSON output as the default?
Have you tried this?