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
PropertyNamingStrategy translates property names of properties that should not be visible #296
Comments
hi @etay2000 thanks for raising this issue along with a testcase! It does indeed seem like odd behavior. I'll try to look into this issue soon. |
@etay2000 I was able to reproduce the issue you described using Yasson 1.0.4, but when I swapped to Yasson 1.0.5-SNAPSHOT it works fine. I'll add a test for this anyway and we can aim to put out a Yasson 1.0.5 release in the next week or so. |
@aguibert That's good to hear, and thanks for the quick response! Just to clarify when you say it works fine, do you mean that PropertyNamingStrategy is no longer called for invisible properties or just that there no longer appears to be a conflict with the properties colliding? |
yes, when I say it works fine now I mean that: String widget2Json = jsonb.toJson(widget2); now prints: The PropertyNamingStrategy was never inspecting values of the hidden (private) properties, it was just incorrectly noticing that they were there and letting those properties overwrite public properties |
So with the 1.0.5 SNAPSHOT, in the following example, is PropertyNamingStrategy#translateName still called on on both properties?
|
yes, with 1.0.5.SNAPSHOT translateName is still called on both properties |
Is the fact that the NamingStrategy is still translating property names on properties that are never serialized a bug? Even if the translated property name is ignored because the property is not visible it still seems inefficient to do the translation in the first place. |
I wouldn't say it's a bug, but it is a bit inefficient yes. However, I expect the performance impact is negligible. Keep in mind that class parsing only happens on the first time a given So the most important thing for JSON-B performance is that |
Fair enough, perhaps not a bug but maybe an enhancement then? Without digging into the code it seems like it would be as simple as checking property visibility and only conditionally using the naming strategy on visible properties? Either way, thanks for your help. |
Yes it could be a minor enhancement. However, we will be working on the next version of JSON-B soon here, and one of the features being considered is to make JSON-B annotations get processed by default regardless of visibility, which would require Yasson to be looking at private fields once again. |
Ok cool, sounds good to me. |
Currently the PropertyNamingStrategy#translateName method is called on all class fields and methods, regardless of the PropertyVisibilityStrategy assigned. I would assume that those 'invisible' properties would not have any reason to have their property name translated.
This led to another somewhat edge case where using a lowercase PropertyNamingStrategy leads to a property being ignored:
Because the naming strategy changes 'URL' to 'url' in Widget2, it seems to conflict with the private 'url' field, and although no exception is thrown, no value is returned either. According to the default visibility strategy, the private 'url' field should not visible, so is the fact that a 'invisible' field can cause a conflict with a visible public method a separate issue in itself?
The text was updated successfully, but these errors were encountered: