question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

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:closed
  • Created 6 years ago
  • Comments:6 (3 by maintainers)

github_iconTop GitHub Comments

1reaction
benjamin-badercommented, Jan 10, 2018

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 for nobuilder types. Specifically, we’d need to suppress the call to builderFor and modify the generated adapter (created in adapterFor). The tricky part will be modifying GenerateReaderVisitor, which is the class that is responsible for generating deserialization code for each field of a struct/union/exception. It assumes that there is a builder 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.

1reaction
benjamin-badercommented, Jan 9, 2018

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:

struct SearchResult {
  ...
} (thrifty.nobuilders = "true")

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!

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found