-
-
Notifications
You must be signed in to change notification settings - Fork 1.4k
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
Make NumberSerializers.Base public and its inherited classes not final #2116
Comments
This is possible to do for 2.10. I am bit torn on whether allowing extension by sub-classing is a good thing or not (ideally it should not be used), partly because it will then further limit implementation aspects of standard (de)serializers as internal methods become part of semi-public API. On |
I understand your point regarding the default serialization behavior in Java and about the fact that opening too much the code sometimes leads to bad usage. Maybe subclassing is not the right choice and that you may do this by delegation. Regarding In my opinion, an API like Jackson should have a descent behavior — which is the case — but should be enough open so that you may change this behavior, at your own risks. Yes, developers may override a class in a wrong way, but if you have the right documentation along with the right warning, you will have done all you can do so that they have all the material to do the right thing. |
Perhaps I should just add a note in Javadoc stating that while extension is possible, one should be aware that this is not an "official" extension point -- that is, it may work but may be subject to more changes than public API. That is, "only use if you know what you are doing". |
I'm fine with your proposal, I think that this is the right way of doing this. Good news. |
In v2.9.6, I needed to have the
NumberSerializers.FloatSerializer
customized so as to remove the trailing float 0 after the decimal separator when the value is actually an integer, because I could not find a way to configure the Jackson serializer so. Example: I want the "1.0" value to be serialized as "1" and not "1.0".Hence, I wanted to inherit from the
NumberSerializers.FloatSerializer
class, so as to overload theJsonSerializer.serialize(Object value, JsonGenerator generator, SerializerProvider provider)
method, but discovered that:NumberSerializers.Base
class is protected ;NumberSerializers.FloatSerializer
is final.Would it be possible to make the
NumberSerializers.Base
class public and theNumberSerializers.FloatSerializer
not final, please?Indeed, this would make the number serializer more open and prevent from copy/pasting the
NumberSerializers.Base
code when writing a number serializer which overloads the default behavior.The text was updated successfully, but these errors were encountered: