Skip to content
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

Java Transpiled Builder classes to have a method or way to copy the instance #4679

Open
2 tasks
bdoyle0182 opened this issue Oct 22, 2024 · 0 comments
Open
2 tasks
Labels
feature-request A feature should be added or improved. p2

Comments

@bdoyle0182
Copy link

bdoyle0182 commented Oct 22, 2024

Describe the feature

When transpiling from typescript interfaces to java, Jsii creates builder classes for the interface to. We have places in our library where we want to take in an existing pre-built instance of the interface and be able to copy the existing state and make some overrides. Right now it seems the only way is to manually copy all of the existing stateful members of the class into a new builder.

     JsiiClassProps newProps = new JsiiClassBuilder()
          // call all setting methods to copy state like so .myJsiiInterfaceMember(props.getMyJsiiInterfaceMember())
     .build();

versus something like this where the builder can just take the state of the existing inteface object as a common pattern w/ a constructor param

     JsiiClassProps newProps = new JsiiClassBuilder(props)
          .myJsiiInterfaceMemberToOverride(props.getMyJsiiInterfaceMemberToOverride())
     .build();

whereas in typescript this can be easily accomplished already w/ the spread operator on instantiation

Use Case

See description, we regularly need to perform some overrides on an existing base level instance, having to override everything using all of the base level instance member getters is tedious, verbose, and error prone.

Proposed Solution

Have an additional constructor on the builder that takes in an existing instance of the built type T class and creates the initial state of the builder

     JsiiClassProps newProps = new JsiiClassBuilder(props)
          .myJsiiInterfaceMemberToOverride(props.getMyJsiiInterfaceMemberToOverride())
     .build();

Other Information

No response

Acknowledgements

  • I may be able to implement this feature request
  • This feature might incur a breaking change

CDK version used

2.162.1

Environment details (OS name and version, etc.)

MacOS

@bdoyle0182 bdoyle0182 added feature-request A feature should be added or improved. needs-triage This issue or PR still needs to be triaged. labels Oct 22, 2024
@mrgrain mrgrain added p2 and removed needs-triage This issue or PR still needs to be triaged. labels Oct 28, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature-request A feature should be added or improved. p2
Projects
None yet
Development

No branches or pull requests

2 participants