-
Notifications
You must be signed in to change notification settings - Fork 39
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
Require static importing of some com.fasterxml.jackson.annotation
enums
#910
Merged
Merged
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
00b3d79
StaticImport: add `com.fasterxml.jackson.annotation.JsonCreator.Mode`
arichapn 37588e5
Update test code to reflect Google code style
arichapn a762ac1
StaticImport add `com.fasterxml.jackson.annotation.{JsonFormat.Shape,…
arichapn 03a43a3
Suggestions
Stephan202 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There's more cases like:
@JsonFormat.Shape
.@JsonTypeInfo.As
.@JsonTypeInfo.Id
.@JsonSubTypes.Type
.Do you think we could find a way to handle these in bulk @rickie? :)
Or would you recommend listing (and testing) each one individually.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No we do not need to test all of them. The check is already sufficiently tested.
We can simply add the members to the list. I'm not sure if we should just add all of them. We only add the ones where statically importing doesn't make the code "less readable/understandable", as in, we do not lose any context on what is happening.
JsonFormat.Shape
seems like a no-brainer that we should add..Id
I"m not sure:@JsonTypeInfo(use = JsonTypeInfo.Id.CLASS,
I'd say,JsonTypeInfo
can be omitted but theId
part is maybe still "fine" to have? Same holds for:We can drop
JsonTypeInfo
but having.As
is maybe better? This is a bit up for discussion I feel. WDYT?@Type
is not that clear where it comes from. On the other hand, all usages are only nested in the@JsonSubTypes
annotation (I think) and in that case it would make sense.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I agree with your proposal 👍
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I took the annotations from the docs, filtered down to the inner classes, and then did quick scans of some uses in public code on GitHub.
If we ignore
JsonCreator.Mode
as it's already addressed, and filter down to only the cases where I primarily saw uses where the qualification provides superfluous context, these are what we're left with:JsonFormat.Shape
JsonInclude.Include
JsonProperty.Access
I'd vote for including those in this PR with the same approach as what's currently here for
JsonCreator.Mode
.I also looked at the other types Enric mentioned, and agree with Rick:
JsonTypeInfo.As
andJsonTypeInfo.Id
, I think we should keep around theAs
andId
bits because of code like thisJsonSubTypes.Type
, I think we should keep around theType
bit because of code like thisSo to summarise, my vote is to add the following changes here:
JsonFormat.Shape.X
-->X
JsonInclude.Include.X
-->X
JsonProperty.Access.X
-->X
JsonTypeInfo.As.X
-->As.X
JsonTypeInfo.Id.X
-->Id.X
JsonSubTypes.Type.X
-->Type.X
What do you guys think?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
And as for testing, I'd say what we already have provides sufficient confidence for the cases where we're removing all qualification. But it's probably a good idea to add a test for one of the cases where we're leaving some qualification (e.g.
JsonTypeInfo.As.X
-->As.X
).There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just saw Enric's emoji response. 😄
Curious to hear your thoughts too @rickie, if this all sounds good then I'll proceed. 👍
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I completely agree with the proposal of which ones to statically import. W.r.t. the ones that are still qualified but not statically imported, I'm not sure if that would fit in this check TBH. I think that should go in the
NonStaticImport
as there we qualify which types to qualify instead of statically import. Although I'm not sure if that also does this rewrite:JsonTypeInfo.Id.X
toId.X
but it does makeX
->Id.X
. 😄Nonetheless, I'd say it's worth checking out.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Gotcha, in that case I'll just add the static import options to this PR.
For the imports which remain (at least partially) qualified, I can keep it on my TODO list to check those out. 🙂
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Added, let me know what you think. 👍