@JsonProperty is a Jackson annotation that sets the JSON name of a Java field, getter, setter or constructor parameter. It controls how a property is written during serialization and matched during deserialization, so Java names such as firstName can map to JSON names such as first_name.
It also marks non-visible members as properties and, with access, makes a property read-only or write-only. One common belief is wrong: defaultValue does not supply a default during deserialization.
The value attribute is the JSON name. Put the annotation on the field, or on the getter and setter.
Jackson links the field, getter and setter into one logical property, so the annotation on the field renames all three. The same annotation works on record components:
If every property needs the same style, a naming strategy is cleaner than annotating each one: mapper.setPropertyNamingStrategy(PropertyNamingStrategies.SNAKE_CASE), or @JsonNaming on the class. In Spring Boot, set spring.jackson.property-naming-strategy=SNAKE_CASE.
For classes without a default constructor, annotate constructor parameters so Jackson knows which JSON property feeds which argument. Records and compiled classes with the -parameters flag can often skip this, but explicit names are safer.
required = true marks a property as mandatory, but Jackson enforces it only for creator (constructor or factory) parameters, and a missing property then fails with a MismatchedInputException. For fields and setters it is only metadata used by schema generators and documentation tools. For ordinary bean validation use Jakarta Validation annotations such as @NotNull.
The Javadoc describes defaultValue as metadata for documentation and schema tools only. Jackson itself ignores it:
To get a default, initialise the field or use a constructor:
An explicit JSON null still overwrites that value. To keep the default for nulls too, add @JsonSetter(nulls = Nulls.SKIP) to the property.
access takes a JsonProperty.Access value:
| Value | Effect |
|---|---|
AUTO | Default, read and write |
READ_ONLY | Written to JSON, ignored when reading |
WRITE_ONLY | Read from JSON, never written |
READ_WRITE | Explicitly both |
WRITE_ONLY is the usual way to keep a password out of responses:
@JsonAlias accepts extra names on input only, useful when an API renamed a field.@JsonIgnore and @JsonIgnoreProperties exclude properties.@JsonInclude(JsonInclude.Include.NON_NULL) omits null values.@JsonPropertyOrder sets the output order.Jackson 3 changes the databind packages to tools.jackson, while the annotations stay in com.fasterxml.jackson.annotation, so code using @JsonProperty generally keeps its imports.
No. Jackson merges field, getter and setter that share a name, so one annotation renames the whole property.
Yes. An explicit annotation marks the member as a property even when it has no getter or setter, because Jackson can use reflection on it.
@JsonProperty defines the name used for both input and output. @JsonAlias adds alternative names accepted only when deserializing.
Yes. On records put it on the component. With Lombok, annotate the field and make sure the annotation is copied to generated constructors if you rely on them.
Use @JsonProperty to rename properties, name constructor parameters and set read-only or write-only access. Do not rely on defaultValue or on required for fields, since Jackson ignores the first and enforces the second only for creators. Use field initialisers and Bean Validation for defaults and checks, and a naming strategy when a whole model follows one convention.