NServiceBus icon indicating copy to clipboard operation
NServiceBus copied to clipboard

Change JsonSerializer for LearningPersistence Saga storage

Open robbaman opened this issue 2 years ago • 2 comments

We're using the LearningPersistence feature in our automated integration tests so that we don't need to build the entire SqlServer infrastructure for our tests, but I just now discovered that while the default Json serializer for the SqlPersistence seems to be the NewtonSoft serializer (as per the docs), but for the LearlingPersistence this is "SimpleJson".

This is causing compatibility issues (the SimpleJson serialiser doesn't seem to work with constructor parameters for instance) that make testing difficult.

Is there a way to make the LearningPersistance also use the NewtonSoft serializer? As this is just for our testing infrastructure it doesn't have to be a full blown feature, if we need to replace features or DI things this is fine, as long as it can be done...

robbaman avatar Feb 03 '22 12:02 robbaman

Hi @robbaman,

The learning persistence is not intended for the scenario you're describing. It is going to be different than what you are using in production, so it's not going to be a good substitute in tests.

In general, we recommend you always test against the actual persisters and transports you're going to use in production.

As a direct answer to your question, no it is not possible to change the serializer that the learning persistence uses.

bording avatar Feb 04 '22 19:02 bording

Hi @bording,

Thanks for getting back to me.

That's too bad. We make extensive use of integration tests that, for sake of simplicity and performance, use the Learning Transport and Learning Persistence. So far the compatibility has been sufficient for it to 'just work', except for the choice of serializer in the Learning Persistence.

For now we've solved the issue by just duplicating the Learning Persistence into our own custom 'IntegrationTestingPersistence', so it's not an immediate problem, but it does require us to make sure it stays compatible so I was just wondering if there was an easy way to just 'replace an interface here or there' and swap out the serializer.

But thanks again for your quick reply.

robbaman avatar Feb 07 '22 08:02 robbaman