-
-
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
Allow creation of custom sub-types of NullNode
, BooleanNode
, MissingNode
#1799
Comments
Interesting. Yes, from sub-classibility viewpoint it would make sense to allow use. But one thing I have to think about is versioning -- in theory this is something that changes API, and should not go in a patch. But the practical concern is that 2.9 is the last 2.x minor version, and 3.0 will take a while. So I may make an exception here; it is not part of public API, either, so it's probably ok. |
Thanks @cowtowncoder . To be clear, protected constructors wouldn't help me, since they wouldn't be accessible in my code. One way to do this without changing the public API would be to give the new constructors package visibility (or more) and create new protected methods in
My custom factory, deriving from P.S. Technically, I could use protected constructors by creating my own class in the P.P.S. Speaking of gross hacks, it just occurred to me that I can get access to the private constructors now through reflection. Doing that - and gracefully degrading if the security manager doesn't allow it - might be a reasonable intermediate approach until my needs are met in Jackson. |
Right, protected constructors would allow sub-classing, that's what I was thinking. Alternatively I could just add a separate factory method in |
@cowtowncoder Ah, I get it. My starting point is a custom Focusing on just I didn't make the obvious leap to creating my own custom So yes, protected constructors on |
@andylowry Right, makes sense. Apologies for slow progress here. Will try to add |
@cowtowncoder Thanks, much appreciated. |
NullNode
, BooleanNode
, MissingNode
The JsonNodeFactory instance always uses canonical instances for certain values of certain node types, including empty arrays, empty objects, ints from -1 to 10, booleans, maybe others.
I have a use-case where I need to parse a JSON/YAML file to a
JsonNode
tree and use the nodes as keys in an IdentityHashMap. The canonical instances were, naturally, causing problems.I've created my own factory and installed it in my mapper instances, and that works great. But I can't currently avoid canonical instances of
BooleanNode
,NullNode
andMissingNode
, because none of them have a visible constructor (so I can't call the constructors, and I can't extend the types).I don't actually have a need for non-canonical
MissingNode
, and my inability to manufacture non-canonical boolean and null nodes is something I can live with (that prevents an unlikely edge-case for my application from working correctly, but I can document that and leave it as is for now).Adding public constructors to these types would make it possible for me to complete my custom factory. Making existing constructors package-visible and adding a
DeserializationFeature
that avoids canonical instances would probably be even better.The text was updated successfully, but these errors were encountered: