Skip to content

Add rebuild patter to reuse instance of class#1139

Merged
l-trotta merged 2 commits into
mainfrom
rebuild-pattern
Jan 16, 2026
Merged

Add rebuild patter to reuse instance of class#1139
l-trotta merged 2 commits into
mainfrom
rebuild-pattern

Conversation

@l-trotta

@l-trotta l-trotta commented Jan 16, 2026

Copy link
Copy Markdown
Contributor

Closes #529, closes #91.
Using the rebuild() pattern inspired by https://github.com/FasterXML/jackson-core to allow taking an instance of a class (excluding responses and abstract classes) and reverting it back to it's builder, keeping the already existing field values.

Usage example:

 SearchRequest searchRequest = SearchRequest.of(s -> s
     .size(20)
     .index("test")
     .query(q -> q.match(m -> m.field("field").query("value")))
 );
 SearchRequest.Builder builder = searchRequest.rebuild();

 SearchRequest searchRequestRebuilt = builder
    // can update values here
   .build();

@l-trotta
l-trotta merged commit 7e39fa7 into main Jan 16, 2026
17 checks passed
@l-trotta
l-trotta deleted the rebuild-pattern branch January 16, 2026 15:03
@github-actions

Copy link
Copy Markdown

The backport to 8.19 failed:

The process '/usr/bin/git' failed with exit code 1

To backport manually, run these commands in your terminal:

# Fetch latest updates from GitHub
git fetch
# Create a new working tree
git worktree add .worktrees/backport-8.19 8.19
# Navigate to the new working tree
cd .worktrees/backport-8.19
# Create a new branch
git switch --create backport-1139-to-8.19
# Cherry-pick the merged commit of this pull request and resolve the conflicts
git cherry-pick --mainline 1 7e39fa77228d24e07d63ad66dc80e92a736028b0
# Push it to GitHub
git push --set-upstream origin backport-1139-to-8.19
# Go back to the original working tree
cd ../..
# Delete the working tree
git worktree remove .worktrees/backport-8.19

Then, create a pull request where the base branch is 8.19 and the compare/head branch is backport-1139-to-8.19.

@github-actions

Copy link
Copy Markdown

The backport to 9.1 failed:

The process '/usr/bin/git' failed with exit code 1

To backport manually, run these commands in your terminal:

# Fetch latest updates from GitHub
git fetch
# Create a new working tree
git worktree add .worktrees/backport-9.1 9.1
# Navigate to the new working tree
cd .worktrees/backport-9.1
# Create a new branch
git switch --create backport-1139-to-9.1
# Cherry-pick the merged commit of this pull request and resolve the conflicts
git cherry-pick --mainline 1 7e39fa77228d24e07d63ad66dc80e92a736028b0
# Push it to GitHub
git push --set-upstream origin backport-1139-to-9.1
# Go back to the original working tree
cd ../..
# Delete the working tree
git worktree remove .worktrees/backport-9.1

Then, create a pull request where the base branch is 9.1 and the compare/head branch is backport-1139-to-9.1.

@github-actions

Copy link
Copy Markdown

The backport to 9.2 failed:

The process '/usr/bin/git' failed with exit code 1

To backport manually, run these commands in your terminal:

# Fetch latest updates from GitHub
git fetch
# Create a new working tree
git worktree add .worktrees/backport-9.2 9.2
# Navigate to the new working tree
cd .worktrees/backport-9.2
# Create a new branch
git switch --create backport-1139-to-9.2
# Cherry-pick the merged commit of this pull request and resolve the conflicts
git cherry-pick --mainline 1 7e39fa77228d24e07d63ad66dc80e92a736028b0
# Push it to GitHub
git push --set-upstream origin backport-1139-to-9.2
# Go back to the original working tree
cd ../..
# Delete the working tree
git worktree remove .worktrees/backport-9.2

Then, create a pull request where the base branch is 9.2 and the compare/head branch is backport-1139-to-9.2.

@github-actions

Copy link
Copy Markdown

The backport to 9.3 failed:

The process '/usr/bin/git' failed with exit code 1

To backport manually, run these commands in your terminal:

# Fetch latest updates from GitHub
git fetch
# Create a new working tree
git worktree add .worktrees/backport-9.3 9.3
# Navigate to the new working tree
cd .worktrees/backport-9.3
# Create a new branch
git switch --create backport-1139-to-9.3
# Cherry-pick the merged commit of this pull request and resolve the conflicts
git cherry-pick --mainline 1 7e39fa77228d24e07d63ad66dc80e92a736028b0
# Push it to GitHub
git push --set-upstream origin backport-1139-to-9.3
# Go back to the original working tree
cd ../..
# Delete the working tree
git worktree remove .worktrees/backport-9.3

Then, create a pull request where the base branch is 9.3 and the compare/head branch is backport-1139-to-9.3.

@l-trotta

Copy link
Copy Markdown
Contributor Author

skipping backporting in favor of just regenerating the branches with the new generator changes.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

How to Reuse a “builder” Converting a request/response back to its builder

1 participant