0

I'm storing objects in my saga data that have properties that should be ignored during serialization and deserialization. I've tried marking these properties with both [NonSerialized] and [JsonIgnore] (and annotating the classes with [DataContract] and not making those properties [DataMember]...) and nothing seems to do the trick. No matter what I do, when NServiceBus calls Json.NET to persist the saga data all the properties get serialized. I've also tried implementing a custom JsonConverter for the objects in question, and that gets ignored as well (yes, I'm annotating the object type with [JsonConverter(typeof(MyConverter))]...)

Is there a way to get saga persistence to ignore a property in an object contained within the saga data? For reference, I'm using NServiceBus 3.2.7, Json.NET 4.5.7, and RavenDB build 960. The bus is configured to use RavenDB persistence and saga persistence.

ivern
  • 131
  • 6
  • I know you probably don't want to hear this - but why are you doing this? :-) – Pete Montgomery Aug 15 '12 at 15:27
  • I have a complex task that's subdivided into a large number of smaller tasks. The results of the smaller tasks need to be combined into the result of the overall complex task. So I store the results of the smaller tasks in the saga data for this purpose. The reason why some properties shouldn't be serialized is that they contain relatively heavyweight data that I don't want to persist. I *could* refactor the saga so that only the relevant data (a changeset) is persisted in the saga data, and I probably will do this later on, but I don't understand why I can't just [JsonIgnore] for now. – ivern Aug 15 '12 at 16:05
  • Yes. I'm afraid I don't know the answer to why NonSerialized is ignored, but it doesn't make sense to me that you have saga data that isn't saga data, if you see what I mean. – Pete Montgomery Aug 15 '12 at 16:18

1 Answers1

0

NServiceBus internalize both the raven client and json.net. That is why those attributes don't work(they are essentially different types since we merge with the internal flag). The workaround is to use the core only version of nsb that isn't merged. That said I'm curious why you need those extra properties?

Andreas Öhlund
  • 5,263
  • 20
  • 24
  • I'm storing business object writers in the saga data, which are combined and sent back to the caller once the saga completes. The writers normally contain the base object data + a dictionary of changes to it. The base data can be very big and is not needed since the caller already has it, so it doesn't need to actually be stored in the saga data. What I suppose I'll do is refactor things a bit so I'm only storing the dictionaries of changes in the saga data, instead of the business objects with non-serializable fields. Thanks. – ivern Aug 15 '12 at 19:49
  • I'll mark your answer as valid as you've helped me understand why the attributes aren't working. Thanks again. – ivern Aug 15 '12 at 19:51