1

Using this method: Override field name deserialization in ServiceStack I am able to override field names. Is there an alternative where I don't have to use DataContract? I'd like to be opt-out serialization.

Edit: as stated in comments below, this is not available by design to match the rest of .NET.

Community
  • 1
  • 1
joe
  • 1,125
  • 9
  • 18

1 Answers1

0

You can use [IgnoreDataMember] to make it opt out and omit adhoc fields.

Bhushan Firake
  • 9,338
  • 5
  • 44
  • 79
mythz
  • 141,670
  • 29
  • 246
  • 390
  • I mean, I need it to be op-out serialization, but I have to rename the property. DataMember(Name = "MyField") doesn't seem to work without DataContract on the class, which I'd rather not use. – joe Nov 18 '12 at 03:28
  • I don't understand what behavior you're looking for? Why do you need a field renamed if you don't want it serialized? exactly why are you renaming it if it's not for Serialization? Are you looking for some existing `[DataContract]` behavior you want replicated in SS text serializers? is this a feature/behavior available somewhere else? – mythz Nov 18 '12 at 03:36
  • I'd like to not use DataContract, so everything is serialized by default. But I also need a property renamed. – joe Nov 18 '12 at 03:54
  • In that case, No there is no alternative attribute for renaming a field. You could add another getter returning the renamed field you want, but then you'll have both fields serialized. – mythz Nov 18 '12 at 03:59
  • Ah thanks. Is this by design, or are you looking for patches for this behavior? – joe Nov 18 '12 at 04:00
  • It's by design because ServiceStack's Text serializers mimic the behavior of .NET's default `[DataContract]` attributes and adding an alternative will be non-standard and redundant. I would personally avoid having to rename fields which just adds artificial complexity, ideally you'll have separate DTOs which never need to be renamed since they are already in the shape of the wire format you want (i.e. the purpose of DTOs). – mythz Nov 18 '12 at 04:05