-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Fixes for custom serialization settings #2189
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
Previously, ModifyJsonSerializationSettings() did not respect properties initialized in a custom serializer's constructor, since it was being called in the base class constructor. This is bad practice (hence the ReSharper warning). This change moves all of the initialization code that was in the ctor to a new method Initialize() which must be called after the serializer is instantiated. This change also fixes another issue where our stateful converters were totally disregarding any registered custom serializer. For this reason, Initialize() also accepts an optional JsonConverter which is used to return a new serializer (custom or default) with the stateful converter applied. Relates #2183 Relates #2182
The only obvious downside to this approach is the need to call I still think it's a better trade-off rather than calling |
Thanks @gmarz for looking into this so quickly! I'm not familiar enough with NEST's threading model, but it seems calling Perhaps a new overload to |
Another possible approach: what if we extract the settings creation to a factory object, which gets passed into the JsonNetSerializer? This would change the constructor to something like this:
This eliminates the initialization order problem by moving the pertinent data outside of the JsonNetSerializer. It does, however, make things a bit strange, since we're dictating behavior via the passed-in Factory, yet also dictating behavior via overloaded methods (I assume there will be no changes to other methods). Thoughts @mitchknife @gmarz ? |
You're absolutely right about that @mitchknife,
@tsliang the factory seems like a good approach, but I don't think there's a way to introduce it without breaking the API in 2.x? |
@gmarz Adding the lock within
The lock needs to live for the duration of the (de)serialize call.
My thought was that the Better yet, wrap the original |
True that. To be honest, I don't like the idea of using locks or this approach at all. I think it's back to the drawing board entirely with this change. |
Closing in favor of #2197 |
Taking another approach then #2189. Here we yield responsibility of creating a new client to ISerializerFactory. The overloads taking a Func factory are now obsolete and others taking ISerializerFactory are added applied feedback on #2197 fix null reference is test setup post switch to serializerfactory
Taking another approach then #2189. Here we yield responsibility of creating a new client to ISerializerFactory. The overloads taking a Func factory are now obsolete and others taking ISerializerFactory are added applied feedback on #2197 fix null reference is test setup post switch to serializerfactory
Taking another approach then #2189. Here we yield responsibility of creating a new client to ISerializerFactory. The overloads taking a Func factory are now obsolete and others taking ISerializerFactory are added applied feedback on #2197 fix null reference is test setup post switch to serializerfactory
Previously, ModifyJsonSerializationSettings() did not respect properties
initialized in a custom serializer's constructor, since it was being
called in the base class constructor. This is bad practice (hence the
ReSharper warning). This change moves all of the initialization code
that was in the ctor to a new method Initialize() which must be called
after the serializer is instantiated.
This change also fixes another issue where our stateful converters were
totally disregarding any registered custom serializer. For this reason,
Initialize() also accepts an optional JsonConverter which is used to
return a new serializer (custom or default) with the stateful converter
applied.
Relates #2183
Relates #2182