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.

Getters for Builder

See original GitHub issue

I have constructed a Charge builder like below,

ChargeCreateParams.Builder chargeCreateParamsBuilder = new ChargeCreateParams.Builder();

		chargeCreateParamsBuilder.setAmount(Long.valueOf("100"));
		chargeCreateParamsBuilder.setDescription("desc");
		chargeCreateParamsBuilder.setCurrency("USD");
		chargeCreateParamsBuilder.putMetadata("CompanyName", "Stripe");
		chargeCreateParamsBuilder.putMetadata("Designation", "Remote Dev");

Before building the builder using chargeCreateParamsBuilder.build(), at some point of time, say for ex, I need to verify whether I had set a meta data in the builder.(another ex, Maybe I might be validating the value set in the builder after some time)

I now need to retrieve all the values set as Meta data in the builder. As of now, I am not able to retrieve the vaules set in the Builder object.

There is no support to retrieve the nodes set in the builder.

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Comments:7 (4 by maintainers)

github_iconTop GitHub Comments

1reaction
ob-stripecommented, Oct 16, 2019

I’ve given this a bit more thought and I think getters directly on builder classes are rather uncommon and a bit of a violation of the single responsibility principle.

In version 13.2.0, we’ve added getters on the resulting parameters classes (i.e. the classes that are returned by the parameters builders). Would that work for your use case, @Thilakeswar? You’d be able to do something like this:

ChargeCreateParams.Builder chargeCreateParamsBuilder = new ChargeCreateParams.Builder();
chargeCreateParamsBuilder.setAmount(Long.valueOf("100"));
// etc.

Long amount = chargeCreateParamsBuilder.build().getAmount();
// do whatever validation is needed

// finally build the "real" parameters class instance that you'll use for your API request
ChargeCreateParams chargeCreateParams = chargeCreateParamsBuilder.build();
1reaction
ob-stripecommented, Jul 27, 2019

I think this is a reasonable request. No promises as to when we’ll get to it, but let’s keep this open for now.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Is it strange for a Builder object to have getter methods?
I think there is nothing wrong per se to have getters in your builder class allowing to inspect which data was passed in....
Read more >
How to generate getters for lombok Builder? - Stack Overflow
When trying to use a getter on a builder, e.g. MyEntityBuilder.getName() , IDEA states that it "Cannot resolve method".
Read more >
@Getter and @Setter - Project Lombok
A default getter simply returns the field, and is named getFoo if the field is called foo (or isFoo if the field's type...
Read more >
Lombok Builder with Custom Setter - Baeldung
In this tutorial, we'll take a look at how Lombok's @Builder annotation works and how we can customize it for our specific needs....
Read more >
Generate getters in the Builder class · Issue #432 - GitHub
Sometimes there is a need to access to a Builder getter to do extra logic. @Value.Immutable public abstract class Foo { public abstract ......
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