Can I get ServiceStack to serialize specific properties as XML attributes instead of elements?

91 views Asked by At

My ServiceStack API is returning the following XML:

<UserResult>
  <Email>[email protected]</Email>
  <Forenames>Daniel</Forenames>
  <Href>/users/00000001-0000-0000-0000-00000000000d</Href>
  <Memberships>
    <Href>/users/00000001-0000-0000-0000-00000000000d/memberships</Href>
  </Memberships>
  <Surname>Dare</Surname>
  <UserGuid>00000001-0000-0000-0000-00000000000d</UserGuid>
  <Username>test_dan</Username>
</UserResult>

I'm curious as to whether I can modify the XML serialization so it returns the HREF properties as attributes rather than elements:

<UserResult href="/users/00000001-0000-0000-0000-00000000000d">
  ...
  <Memberships href="/users/00000001-0000-0000-0000-00000000000d/memberships" />
  ...
</UserResult>

or even override the default serialization entirely so that particular properties are exposed as <link /> elements:

<UserResult href="/users/00000001-0000-0000-0000-00000000000d">
  ...
  <link rel="memberships" href="/users/00000001-0000-0000-0000-00000000000d/memberships" />
  ...
</UserResult>

I'm undecided as to whether I should do this, but very curious to know whether it's possible - either by decorating the properties or by replacing the default XML serializer (DataContractSerializer?) used by ServiceStack.

0

There are 0 answers