-
Notifications
You must be signed in to change notification settings - Fork 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
THRIFT-5544: add java code gen param to support including field annotation as metadata #2553
Conversation
a927503
to
a4089f9
Compare
There were similar approaches a while ago and my (personal) feelings about automated C++ code formatting tools abilities are, well, let's call it "mixed feelings". But it's not only a C++ specific thing, I had the same experience with other tools and other languages as well. Sometimes the problems start with the style guide supplied by the manufacturer itself that ist a) the default and b) horribly broken. (Yes, I'm looking at you, Emba). The best tool I've seen in that regard is surely |
@Jens-G did you mean to comment on #2559 (comment) instead? |
I'd say that both rustfmt and gofmt are in this category and it contribute to the fact that Rust's one of the most love languages (per stackoverflow) |
Probably. Must have confused open tabs. |
337b061
to
4531c99
Compare
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 think this could use a larger explanation. From these changes, including the added help documentation in the generator options, it's not clear what 'annotation metadata' is. What are common examples of annotation metadata, and how would these be used? The JIRA doesn't have any details in it, either: https://issues.apache.org/jira/browse/THRIFT-5544
@ctubbsii thanks for the comment. detailed explanation added to jira ticket and inline |
Thanks for the additional information. However, I'm still confused. Is this intended to serialize information about Java annotations I'm just not clear on the end-to-end use of this. Do you have a simple example? |
4531c99
to
33dae90
Compare
@ctubbsii i created a simple example at https://gist.github.com/Jimexist/7acffaa0c4967193937a05f56098853b with the newly added flag in this pull request. |
Thanks. That example helps clear up some things. I was confused by the use of the terms "java" and "field annotation", because I was thinking Java's Field I would call these "tags" rather than "annotations", in order to reduce confusion. However, if this is already an existing IDL language construct, then the name may already be established as "field annotations". If that's the case, I can propose some slight wording improvements in the gen-java parameter help doc. |
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.
Here's some proposed naming / phrasing changes to clear up potential confusion.
This comment was marked as duplicate.
This comment was marked as duplicate.
1 similar comment
I agree it's confusing but i guess that ship is sailed: the name in C++ and also in all of the file names it's named as "annotation". I guess the best method is to try best to make it less ambiguous in Java. |
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 have only this last final suggestion to help further clarify things in the documentation. But otherwise, this looks great to me.
e7d1365
to
b14e82a
Compare
had to do a rebase onto master due to conflict. |
seems like the build failure was due to |
b14e82a
to
933287a
Compare
933287a
to
1384045
Compare
now this is fixed, ready for merging |
add java code gen param to support including field annotation as metadata
Currently the code generator has a map of string to string field that denotes the "annotations" for a field:
thrift/compiler/cpp/src/thrift/parse/t_field.h
Line 109 in 90ea2e8
It is made available to generators such as JSON (in
thrift/compiler/cpp/src/thrift/generate/t_json_generator.cc
Lines 267 to 274 in 90ea2e8
In Java, similar mechanism exists to register field metadata (via
thrift/compiler/cpp/src/thrift/generate/t_java_generator.cc
Lines 2862 to 2865 in 90ea2e8
org.apache.thrift.meta_data.FieldMetaData#addStructMetaDataMap
method to register into a centralized places. Such metadata is useful, e.g. the microservice framework Ameria uses it to dynamically proxy requests.However the existing field metadata only contain information about field id, type, and name, but it does not contain annotations. Adding annotations will be useful for situations e.g. (these are useful enablement at user side, make possible if annotation is included)
deprecated
means in the context of a field, addingobfuscated
allows the user site to decide to obfuscate detailed informationdate_format="YYYY-MM-DD"
allows the thrift struct to be interpreted as a local date and thus can automatically be converted to java.time.LocalDateThis should be a back-compatible change as the default behavior is not to include the annotation. A second constructor can be added to allow included annotation to exist and register.
[skip ci]
anywhere in the commit message to free up build resources.