-
-
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
Deprecated JsonNode.with(String) suggests using JsonNode.withObject(String) but it is not the same thing #3780
Comments
Faced the same issue. I think, adding "/" before every property is a bad idea. Because each withObject() call will cause JsonPointer.compile() on your property, which significantly decrease performance.
Otherwise, migration to Jackson 3 will be very painful for many users like me, who often uses .with("property") method. |
Ok, I do not think it is a good idea at all to overload "property-or-expression" because two sets are overlapping -- even if it is not common, one can definitely use empty String as property name, or something starting with slash. Situation with Having said that, I am to addition of, say, 2 new methods that only allow property would make sense:
and I'd be happy to help merge a PR, based on code sample @tanis138 shared for example. |
Backwards compatibility is creating all this mess. For this purpose, "property-or-expression" fits best. |
I will not be adding any new "property-or-expression" functionality, fwtw. I think that is a bad idea and I will try to eventually get rid of such logic; for now (2.x) functionality will be retained for backwards-compatibility. I also dislike overloads for This is why the way forward to me is addition of 2 new methods. And due to need to produce array or object nodes, need 2 instead of generic |
On |
If it helps, I solved it like this (withObject):
with this method of JsonNode.class (jackson-2.15.x) public final ObjectNode withObject(JsonPointer ptr) { |
I'd like to chime in on this one as well. We were in the process of replacing I 2.13 To be honest, it makes it a bit cumbersome because e.g. customer.withArray("addresses"); customer.with("address"); but if I do customer.withObject("address"); then it doesn't work. If 2 new methods are added then @cowtowncoder is it an option to make |
Deprecation was to address inconsistencies and my (seemingly mistaken) thinking that most access would be with multiple-level expressions, not "simple" property name. I also dislike heuristics of "property-or-json-pointer-expr". |
After reading this through again, I suspect that changing |
Thanks for taking our feedback into consideration @cowtowncoder |
Is your feature request related to a problem? Please describe.
Version
2.14
deprecatedJsonNode.with(String)
and suggests replacing it withJsonNode.withObject(String)
. However, this causes problems becauseJsonNode.withObject(String)
accepts only expressions, whereas the former method accepts a property. Moreover,JsonNode.withArray(String)
accepts both property names and expressions, making it quite asymmetric.Describe the solution you'd like
Migrating the method would imply in many cases extra work and prepending the "/" before every property name in existing calls.
From the deprecation message of
JsonNode.with(String)
I would changemyObj.with(myProp)
tomyObj.withObject(myProp)
but that throws an exception, so I have to domyObj.withObject("/" + myProp)
, which I find unpleasant. Again,myObj.withArray(myProp)
works just fine without need of change.Usage example
The change from
myObj.with(myProp)
tomyObj.withObject(myProp)
should work with property or expression.The text was updated successfully, but these errors were encountered: