Java Configuration

You can customize the behavior of the Java SDK generator in generators.yml:

generators.yml
1groups:
2 java-sdk:
3 generators:
4 - name: fernapi/fern-java-sdk
5 version: 3.5.3
6 config:
7 client-class-name: YourApiClient

SDK Configuration Options

base-api-exception-class-name
string

Customizes the name of the base API exception class that all API-specific exceptions will extend. This allows you to define a custom base exception class name for better integration with your existing error handling patterns.

base-exception-class-name
string

Specifies the name of the base exception class that all generated exceptions will inherit from. This provides a common parent class for all SDK exceptions, enabling consistent exception handling patterns.

client-class-name
stringDefaults to <Organization>ApiClient

The provided string will be used as the client class name.

custom-dependencies
List<string>

Example:

1custom-dependencies:
2- "implementation com.foo:bar:0.0.0"
3- "testImplementation com.foo:bar:0.0.0"
4- "api com.foo:bar:0.0.0"
disable-required-property-builder-checks
booleanDefaults to false

When enabled, disables validation checks in builder patterns for required properties. This removes compile-time checks that ensure all required fields are set before building an object, providing more flexibility but less safety.

enable-extensible-builders
booleanDefaults to false

When enabled, generates extensible builder classes that support customization through inheritance. This allows you to add custom code to extend the generated builders with additional functionality.

enable-forward-compatible-enums
booleanDefaults to false

When enabled, generates enum classes that can handle unknown values gracefully. This allows the SDK to process new enum values that may be added to the API without breaking existing client code, improving forward compatibility.

enable-inline-types
booleanDefaults to false

When enabled, generates inline types for nested schemas instead of creating separate classes. This results in cleaner type definitions where nested objects are defined within their parent types, reducing the number of generated files.

enable-public-constructors
booleanDefaults to false

When enabled, generates public constructors for model types.

generate-unknown-as-json-node
booleanDefaults to false

When enabled, generates unknown or untyped properties as structured JSON objects instead of raw Object types. This provides better type safety and easier manipulation of dynamic JSON content while maintaining flexibility for unknown data structures.

inline-file-properties
booleanDefaults to false

Controls whether file upload properties are generated as inline request properties instead of separate method parameters. When enabled, file fields become part of the request object rather than being passed as individual function arguments.

inline-path-parameters
booleanDefaults to false

When enabled, path parameters are included as properties in the request object instead of being passed as separate method parameters. This creates a more unified request structure where all parameters are grouped together.

json-include
'non-empty' | 'non-absent'Defaults to non-absent

Controls Jackson’s JSON serialization behavior for optional fields. Use ‘non-empty’ to exclude null and empty values, or ‘non-absent’ to only exclude null values while preserving empty collections and strings.

package-layout
'nested' | 'flat'Defaults to nested

Determines the organization of generated Java packages. Choose ‘nested’ for a hierarchical package structure that mirrors your API organization, or ‘flat’ for a simpler structure with fewer nested packages.

package-prefix
string

By default, the generated SDK will use the package prefix com.{orgName}.api, where {orgName} is your Fern organization name (defined in fern.config.json). To override this, you can specify the package-prefix field in your generators.yml configuration.

config:
package-prefix: my.new.package
publish-to
'central' | 'ossrh'

Publish target for Maven packages. Use central for Maven Central Portal or ossrh for legacy Nexus Repository.

wrapped-aliases
booleanDefaults to false

When enabled, generates wrapper types for each alias to increase type-safety. For example, if you have an alias ResourceId: string then if this is true, the generator will generate a ResourceId.java file. If false, it will just treat it as java.util.String.

Publishing metadata configuration options

If you want to customize how your publishing metadata looks in your build.gradle file, update the metadata field in generators.yml.

1 generators:
2 - name: fernapi/fern-java-sdk
3 version: 2.7.0
4 metadata:
5 author: "AuthorName"
6 email: "example@email.com"
7 package-description: "Your site description here"
8 reference-url: "https://example.com"
9 license: "MIT"
author
string

Specifies the author name that will appear in the generated package metadata and build configuration files.

email
string

Sets the contact email address for the package author that will be included in the generated package metadata.

license
'MIT' | 'Apache-2.0' | { custom: 'Custom License Name' }

Defines the software license for the generated SDK. Choose from standard licenses like ‘MIT’ or ‘Apache-2.0’, or specify a custom license name.

package-description
string

Provides a description of the SDK package that will appear in package metadata and documentation. This helps users understand what the SDK is for and its purpose.

reference-url
string

Sets the reference URL (typically the API documentation or project website) that will be included in the package metadata for users to find additional information.