Optionally suppress generated Builder types
See original GitHub issue// Let's call this example.thrift
namespace java com.foo.bar
struct Query {
1: required string text,
2: optional i64 resultsNewerThan
}
struct SearchResult {
1: required string url,
2: required list<string> keywords = [], // A list of keywords related to the result
3: required i64 lastUpdatedMillis // The time at which the result was last checked, in unix millis
}
service Google {
list<SearchResult> search(1: Query query)
}
In the example above we need builder only for Query
as the value for the search result is populated by deserializer. Looking at the code there is no easy way to distinguish if the model is request/response
type. Any idea on how to go around it?
Issue Analytics
- State:
- Created 6 years ago
- Comments:6 (3 by maintainers)
Top Results From Across the Web
@Builder - Project Lombok
Each listed generated element will be silently skipped if that element already exists (disregarding parameter counts and looking only at names). This includes ......
Read more >How to exclude property from Lombok builder? - Stack Overflow
First, we move the fields to be excluded into an Inner Class to avoid Lombok from including them in the Builder. Then, we...
Read more >Immutable objects
Using “forwarding” factory methods and abstract builders, it is possible to hide the generated implementation type and its builder from the API.
Read more >How to solve the Builder pattern's boilerplate problem
Clicking on the button will (optionally) show you the list of fields to choose from to use in the builder. The code is...
Read more >Builder options - Drift - Simon Binder
In general, we recommend using the default options. However, you can disable some default drift features and reduce the amount of generated code...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
This sort of thing would apply to structs, unions, and exceptions - all of these have generated builders.
The implementation would be “straightforward” - in
ThriftyCodeGenerator#buildStruct
, add a separate code path fornobuilder
types. Specifically, we’d need to suppress the call tobuilderFor
and modify the generated adapter (created inadapterFor
). The tricky part will be modifyingGenerateReaderVisitor
, which is the class that is responsible for generating deserialization code for each field of a struct/union/exception. It assumes that there is abuilder
involved, which would no longer be guaranteed - either we’ll need a variant of this visitor that doesn’t use builders, or this one should be rewritten to never use builders.The latter approach would be simpler, and could potentially make generated code much more proguard-friendly.
I haven’t thought deeply about this, so it’s possible that I’ve missed an important edge-case here.
That’s an interesting question. There isn’t any way to strip out the
Builder
types; the generated adapter code uses them to implement deserialization.I’d never thought about
request/response
types before, because Thrift itself makes no such distinction; it’s more of an application-specific label. It’s an interesting idea though, and one I could see being implemented, for example:It would be a relatively big job, and I don’t have the time to implement it. I’d be happy to talk design and coach someone through a PR, though!