Repository navigation
Property Types
Every property is either a "type" or a "$ref". Any other value for "type" is rejected at load time.
type |
format |
Java type (boxed) | Primitive |
|---|---|---|---|
string |
- | String |
String |
integer |
absent or "int"
|
Integer |
int |
integer |
"long" |
Long |
long |
number |
absent | Double |
double |
number |
"float" |
Float |
float |
boolean |
- | Boolean |
boolean |
bytes |
- | byte[] |
byte[] |
preferPrimitives only downgrades a property that can never be null - one that is required or has a default. An
optional property stays boxed and @Nullable.
A format on a string does not change the Java type; it drives Validation instead
("email", "uuid", "date", "time", "date-time", "decimal").
byte[] is mutable, so ModelMaker defends the array at every boundary:
private final byte[] payload;
public byte[] getPayload() {
return payload.clone(); // callers never see the stored array
}- The builder setter clones the caller's array on the way in.
- Every getter returns a clone.
- A
withXyzreplacement clones too. -
equals/hashCodeuseArrays.equals/Arrays.hashCode- content, not identity. -
toStringprints the base64 form, viaBase64.getEncoder(). - Jackson serializes
byte[]as a base64 string out of the box. -
"default"is not supported forbytes.
"tags": {
"type": "array",
"maxItems": 10,
"items": { "type": "string", "minLength": 1, "maxLength": 40, "pattern": "^[a-z-]+$" }
}renders as List<String> and, with validation on:
@Size(max = 10, message = "size must be at most 10")
public @Nullable List<@Pattern(regexp = "^[a-z-]+$", message = "must match \"^[a-z-]+$\"") @Size(min = 1, max = 40, message = "size must be between 1 and 40") String> getTags() {
return tags != null ? Collections.unmodifiableList(tags) : null;
}Rules:
-
"items"is required; an array without it is rejected. - Arrays of arrays are not supported.
- The builder copies the incoming list (
new ArrayList<>(...)); the getter returnsCollections.unmodifiableList(...). The DTO never aliases a caller's list, and a caller can never mutate the DTO's. -
minItems/maxItemssize theListitself; keywords written inside"items"become container-element annotations on the element type. - A
Listof a generated type gets a@Validcascade on the element whenvalidationis on. - Element annotations render on the field / getter type only. The constructor and the builder keep the plain
List<T>.
"contact": {
"type": "object",
"title": "Contact",
"required": ["email"],
"properties": {
"email": { "type": "string", "format": "email" }
}
}becomes a nested class inside the owning type:
public final class Person {
private final @Nullable Contact contact;
// ...
public static final class Contact {
private final String email;
// fields, constructor, getters, builder, BuilderMutator ...
}
}-
"title"names the class and must be a plain class name - a dotted value is rejected. - Without
"title", the class is named after the capitalized property key (contact→Contact). - Nesting can go deeper; each level produces another nested class.
- A nested object cannot carry its own
features- only the top-level type'sfeaturesapplies to the whole file. - Nested types get the full treatment too: their own builder,
BuilderMutator,equals/hashCode/toString, and their own Kotlinmutate { }extension.
"shippingAddress": { "$ref": "com.example.dto.Address" },
"createdAt": { "$ref": "java.time.Instant" }A $ref resolves to one of three things:
-
Another schema's
title- the generated class for that schema. Cross-checked after loading; an unknown target fails the build. - A nested type's plain name - the inline class declared in the same file.
-
A
java.*/javax.*type - used as-is and imported. Not generated, and not validated for existence -javacreports a bad one.
Notes:
- A same-package reference renders as the simple class name;
java.lang.*targets are used without an import. - A JDK
$refis opaque to ModelMaker: no constraints are derived from it, and it is not cascaded into with@Valid. Whether Jackson can bind it is up to yourObjectMapperconfiguration. -
$refis the escape hatch for anything the type system above cannot express - see FAQ.
-
enumas a Javaenum- rendered as aStringwith a generated@Patternover the allowed values. -
Maps / dictionaries - no mapping. Use a nested object with fixed keys, or a
$refto a JDK type. - Arrays of arrays - rejected at load time.
-
Polymorphism (
oneOf/anyOf/allOf) - not parsed. -
Recursion by inline nesting - an inline
objectis expanded in place, so it cannot nest into itself. A$refcycle between top-level schemas is fine, since refs are resolved by name rather than inlined.
The guiding rule: generated models support the simple types most likely to round-trip cleanly between a Java object and JSON.
ModelMaker - Apache License 2.0 - Issues - Wiki index
Start here
Schemas
Output
Features
Integration
Reference