Java Code Generation
paradox generate --java [--path PATH]
Product Types
Input:
type Person
name: Text
age: Integer
admin: Boolean
Output:
public record Person(String name, long age, boolean admin) {}
Products become Java 17+ records.
Union Types
Simple unions (no payloads) become enums:
union Direction
north
south
east
west
public enum Direction { NORTH, SOUTH, EAST, WEST }
Complex unions (with payloads) become sealed interfaces:
union Cheese
farmers
cheddar
brie: Text
public sealed interface Cheese {
record Farmers() implements Cheese {}
record Cheddar() implements Cheese {}
record Brie(String value) implements Cheese {}
}
Pattern matching uses instanceof:
if (x instanceof Cheese.Brie b) {
// use b.value()
} else if (x instanceof Cheese.Farmers f) {
// ...
}
Wrap Types
wrap Email: Text
public record Email(String value) {
public static Email wrap(String value) { return new Email(value); }
public String unwrap() { return this.value(); }
}
Validators
public static java.util.Optional<String> validatePerson(Person x) {
var errors = new java.util.ArrayList<String>();
// ... validation checks ...
if (!errors.isEmpty()) return java.util.Optional.of(String.join("; ", errors));
return java.util.Optional.empty();
}
Validators return Optional<String> where the string is the error message.
Type Mapping
| Paradox | Java |
|---|---|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|