Skip to content

Property Naming

Damian Malczewski edited this page Sep 10, 2026 · 1 revision

Property Naming

A JSON property key and a Java field name are not the same thing. ModelMaker normalizes the key to a camelCase identifier, keeps the original key for JSON binding, and rejects anything ambiguous up front instead of leaving javac to complain.

Accepted key forms

A key must match one of these forms, optionally prefixed with one or more underscores (e.g. __metadata):

Form Example Regex (after the underscore prefix)
camelCase firstName [a-z][a-zA-Z0-9]*
snake_case first_name [a-z][a-z0-9]*(_[a-z0-9]+)*
UpperCamelCase FirstName [A-Z][a-zA-Z0-9]*

Normalization

  • snake_case segments are joined and capitalized.
  • An UpperCamelCase key is lower-cased on its first letter.
  • A leading-underscore prefix is kept as-is.
Key Field name
firstName firstName
first_name firstName
FirstName firstName
_first_name _firstName
__metadata __metadata

The original key is preserved for @JsonProperty and @JsonPropertyOrder, so the wire format is exactly what the schema said:

"first_name": { "type": "string" }
private final @Nullable String firstName;

@JsonProperty("first_name")
public @Nullable String getFirstName() {
  return firstName;
}

Derived member names

The getter, builder method and wither names come from the field name with its first letter capitalized:

Field Getter Builder method Wither
firstName getFirstName() firstName(...) withFirstName(...)
_firstName get_firstName() _firstName(...) with_firstName(...)

An underscore-prefixed field therefore yields valid Java that is not a JavaBeans-style accessor. Tooling that relies on bean introspection (rather than on the emitted Jackson annotations) may not see such a property.

Rejected at load time

Rejected Why
name_, first__name Trailing or doubled underscore inside the body.
kebab-case, with space, 1st Matches none of the accepted forms.
first_name and firstName in the same object Both normalize to firstName.
_first_name and _firstName in the same object Both normalize to _firstName.

The clash check is per object, so a nested type may reuse a name freely. Exact error messages are on Troubleshooting.

Practical advice

  • Pick one key style per schema and stay with it - the generated Java is identical either way, only the JSON differs.
  • Use the underscore prefix only when the wire format genuinely has one; the resulting accessors are awkward.
  • $ref, type, title and friends are schema keywords, not property keys - they live one level up, inside the property object, never as a property name.

Clone this wiki locally