TypedRest.CodeGeneration.Java 0.3.0

dotnet add package TypedRest.CodeGeneration.Java --version 0.3.0
                    
NuGet\Install-Package TypedRest.CodeGeneration.Java -Version 0.3.0
                    
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="TypedRest.CodeGeneration.Java" Version="0.3.0" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="TypedRest.CodeGeneration.Java" Version="0.3.0" />
                    
Directory.Packages.props
<PackageReference Include="TypedRest.CodeGeneration.Java" />
                    
Project file
For projects that support Central Package Management (CPM), copy this XML node into the solution Directory.Packages.props file to version the package.
paket add TypedRest.CodeGeneration.Java --version 0.3.0
                    
#r "nuget: TypedRest.CodeGeneration.Java, 0.3.0"
                    
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
#:package TypedRest.CodeGeneration.Java@0.3.0
                    
#:package directive can be used in C# file-based apps starting in .NET 10 preview 4. Copy this into a .cs file before any lines of code to reference the package.
#addin nuget:?package=TypedRest.CodeGeneration.Java&version=0.3.0
                    
Install as a Cake Addin
#tool nuget:?package=TypedRest.CodeGeneration.Java&version=0.3.0
                    
Install as a Cake Tool

TypedRest Code Generation for Java

Generates Java source code for TypedRest for the JVM clients from OpenAPI/Swagger documents.

dotnet add package TypedRest.CodeGeneration.Java

Use this to build your own code generator. If you just want to generate a client for your API, use the command-line tool instead; it is built on this library.

Consuming the client from Kotlin? Generate Kotlin instead, with TypedRest.CodeGeneration.Kotlin. TypedRest for the JVM is written in Kotlin, so that is the lower-friction direction: you get data class DTOs, real null safety and kotlinx.serialization. This package is for projects whose own source is Java.

Usage

var reader = new OpenApiStreamReader(new OpenApiReaderSettings().AddTypedRest());
var doc = reader.Read(File.OpenRead("myapi.yml"), out _);

foreach (var file in doc.GenerateTypedRestJava(new JavaGenerationOptions("MyService")
{
    Namespace = "com.mycompany.myservice",
    GenerateDtos = true
}))
    file.WriteToDirectory("src/main/java/");

GenerateTypedRestJava() uses the endpoints described by the document's x-typedrest extension, or infers them from the paths using TypedRest.CodeGeneration if there is no such extension.

The generated code needs the TypedRest artifacts plus a serializer on the classpath:

dependencies {
    implementation("net.typedrest:typedrest:<version>")
    implementation("net.typedrest:typedrest-serializers-jackson:<version>")
    compileOnly("org.jspecify:jspecify:<version>")
}

Add net.typedrest:typedrest-reactive as well if the document describes any polling or streaming endpoints.

Output

One public type per file, in a directory matching its package, as Java requires. Namespace is the package for the endpoints, defaulting to the service name; DtoNamespace is the package for the DTOs, defaulting to a dtos subpackage of the endpoints.

Endpoints become classes deriving from the TypedRest Impl classes and exposing their children as JavaBean getters over private final fields:

client.getContacts().get("1337").getNote().read();

Each endpoint is built once into the field, so it keeps its response cache across calls.

With GenerateInterfaces each generated endpoint also gets an interface, named the way TypedRest for the JVM names its own: the interface takes the plain name and the class beside it gets the Impl suffix. The getters are then declared on the interface and marked @Override on the class.

DTOs become plain classes with public fields, a no-argument constructor and a full constructor — not records, which need Java 16 and do not suit the serializers' construct-then-populate approach. Schemas with an enum become enums.

A $ref inside allOf is flattened into the type rather than becoming a base class. Every property is still present; only the inheritance relationship is lost.

Nullability

Properties the document does not mark as required are annotated with JSpecify's @Nullable. Without it Kotlin sees every generated type as a platform type and silently drops null safety across the whole DTO surface — exactly where it matters most, since an optional field really can be absent. Turn it off with NullableAnnotations = false if you would rather not take the dependency.

Serializers

Serializer picks which annotations carry the wire names:

Value Type annotation Property annotation Artifact
jackson (default) @JsonProperty net.typedrest:typedrest-serializers-jackson
moshi @JsonClass(generateAdapter = true) @Json(name = ...) net.typedrest:typedrest-serializers-moshi

kotlinx is not available here: kotlinx.serialization generates its serializers with a Kotlin compiler plugin and cannot handle a class written in Java. Asking for it is an error.

Because EntryEndpoint defaults to kotlinx.serialization, a generated Java client always passes its serializer explicitly:

public MyServiceClient(URI uri) {
    super(uri, new JacksonJsonSerializer());
}

Extension points

GenerateTypedRestJava() takes an optional PatternRegistry controlling what is inferred, and an optional BuilderRegistry controlling what is emitted. Both live in TypedRest.CodeGeneration.Jvm and are shared with the Kotlin generator, so a builder you write once affects both.

Product Compatible and additional computed target framework versions.
.NET net5.0 was computed.  net5.0-windows was computed.  net6.0 was computed.  net6.0-android was computed.  net6.0-ios was computed.  net6.0-maccatalyst was computed.  net6.0-macos was computed.  net6.0-tvos was computed.  net6.0-windows was computed.  net7.0 was computed.  net7.0-android was computed.  net7.0-ios was computed.  net7.0-maccatalyst was computed.  net7.0-macos was computed.  net7.0-tvos was computed.  net7.0-windows was computed.  net8.0 is compatible.  net8.0-android was computed.  net8.0-browser was computed.  net8.0-ios was computed.  net8.0-maccatalyst was computed.  net8.0-macos was computed.  net8.0-tvos was computed.  net8.0-windows was computed.  net9.0 was computed.  net9.0-android was computed.  net9.0-browser was computed.  net9.0-ios was computed.  net9.0-maccatalyst was computed.  net9.0-macos was computed.  net9.0-tvos was computed.  net9.0-windows was computed.  net10.0 is compatible.  net10.0-android was computed.  net10.0-browser was computed.  net10.0-ios was computed.  net10.0-maccatalyst was computed.  net10.0-macos was computed.  net10.0-tvos was computed.  net10.0-windows was computed. 
.NET Core netcoreapp2.0 was computed.  netcoreapp2.1 was computed.  netcoreapp2.2 was computed.  netcoreapp3.0 was computed.  netcoreapp3.1 was computed. 
.NET Standard netstandard2.0 is compatible.  netstandard2.1 was computed. 
.NET Framework net461 was computed.  net462 was computed.  net463 was computed.  net47 was computed.  net471 was computed.  net472 was computed.  net48 was computed.  net481 was computed. 
MonoAndroid monoandroid was computed. 
MonoMac monomac was computed. 
MonoTouch monotouch was computed. 
Tizen tizen40 was computed.  tizen60 was computed. 
Xamarin.iOS xamarinios was computed. 
Xamarin.Mac xamarinmac was computed. 
Xamarin.TVOS xamarintvos was computed. 
Xamarin.WatchOS xamarinwatchos was computed. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

NuGet packages

This package is not used by any NuGet packages.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last Updated
0.3.0 38 8/27/2026