Closed ghost closed 6 years ago
I thought I had commented but apparently not.
So, yes, this is problematic. What is missing currently is ability to pass per-serialization settings, especially from databinding (and to a degree from streaming too, since changes to factory can not be done safely wrt multi-threading). I have plans to change this in future, but that'll be Jackson 3.x (after 2.9). In the meantime it would probably make sense to block dangerous change (second one) for sure, and possibly throw exception for misleading case (where call ignored).
I will have to do 2.9.0 without more work, but hope to add some checks/exceptions as per comments. And with 3.0 jackson-core
interaction will be changed in such a way to that parsers and generators will be passed feature settings through constructor, without need to (or ability) to change them. This will allow efficient and safe handling.
As per comments, this now works in master
(for 3.0).
(but note that it will be months until it gets released; and there is no easy fix for 2.x)
SmileGenerator offers the possibility to configure its features after it has been constructed. If you want to enable / disable features on a per-generator approach the following code looks reasonable:
However changing Features after construction is mostly unsupported:
All in all three features cannot be changed, one change is possibly harmful and the last one marginally useful. In my opinion the possibility to change Features for a constructed Generator should be deprecated. At the very least the noop of changing most features after construction should be documented.