NSB5 to NSB7 - JsonSerializer to NewtonsoftSerializer

Hello,

We are testing a project moved from NSB5+JsonSerializer to NSB7+Newtonsoft. I have run into a issue with serializing a type.

Example class -
public class Message1 {
public ICollection<Value1> Value1s {get; set;}
}

public class Value1 {
	public string P1 {get; set;}
}

Value1s property is passed onto another entity and saved into a database. At this point Value1s starts pointing to a NHibernate proxy.

In the message, Value1s is serialized as
“$type”: “NHibernate.Collection.Generic.PersistentGenericBag`1[[Value1]], NHibernate”

This subsequently fails to deserialize.

  1. Were there settings/customizations in JsonSerializer that now need to be applied when using NewtonsoftSerializer?
  2. I tried to find JsonSerializer code on GitHub. Is it available to refer as a starting point?
  3. How do I find all such affected types?

Thanks,
Gursharan

1 Like

Hi Gursharan

Thanks for reaching out.

The Newtonsoft Json documentation page has a dedicated section that talks about the compatibility of the serializer of the built-in one, see https://docs.particular.net/nservicebus/serialization/newtonsoft#compatibility-with-the-core-json-serializer

Could it be related to this guidance available under

https://docs.particular.net/nservicebus/serialization/newtonsoft#compatibility-with-the-core-json-serializer-use-of-type-requires-an-assembly-qualified-name

Regards
Daniel

Hi Daniel,

Thanks for getting back to me on this one.

Yes I think part of the problem is that I expected to replace JsonSerializer with default settings with NewtonsoftSerializer with default settings. They produced similar message format on serialization (with an embedded reference to NHibernate PersistenceBag type) but NewtonsoftSerializer failed to deserialize the message.

Looking at the old JsonSerializer code on GitHub, it has lot of customizations with a MessageBinder and ContractResolver. In our scenarios going down the $type rabbit hole was proving to be a time sink so we have configured NewstonsoftSerializer with different settings that seem to work for our scenarios.

You may close this issue now and I will raise a new one if we run into further issues.

Thanks!
Gursharan