Skip to content

Commit cfaefa5

Browse files
committed
Add builder extension docs to Java custom code
1 parent f9ca7cc commit cfaefa5

File tree

1 file changed

+39
-0
lines changed

1 file changed

+39
-0
lines changed

fern/products/sdks/overview/java/custom-code.mdx

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -104,6 +104,45 @@ description: Augment your Java SDK with custom utilities
104104
</Steps>
105105

106106

107+
## Extending builders
108+
109+
For advanced use cases requiring request transformation or dynamic configuration, you can extend the generated builder classes.
110+
111+
<Steps>
112+
113+
### Override buildClientOptions() to transform configuration
114+
115+
```java title="src/main/java/com/example/CustomClientBuilder.java"
116+
public class CustomClientBuilder extends BaseClientBuilder {
117+
@Override
118+
protected ClientOptions buildClientOptions() {
119+
ClientOptions base = super.buildClientOptions();
120+
121+
// Transform configuration as needed
122+
String transformedUrl = transformEnvironmentVariables(
123+
base.environment().getUrl()
124+
);
125+
126+
return ClientOptions.builder()
127+
.from(base)
128+
.environment(Environment.custom(transformedUrl))
129+
.build();
130+
}
131+
}
132+
```
133+
134+
### Update .fernignore
135+
136+
```diff title=".fernignore"
137+
+ src/main/java/com/example/CustomClientBuilder.java
138+
```
139+
140+
</Steps>
141+
142+
<Callout type="info">
143+
For authentication customization, override the `build()` method instead of `buildClientOptions()`.
144+
</Callout>
145+
107146
## Adding custom dependencies
108147

109148
<Markdown src="/snippets/pro-callout.mdx"/>

0 commit comments

Comments
 (0)