Video in progress

Strong Middle 🌱 Spring

How do you configure Jackson in Spring Boot: dates, null fields, unknown fields?

With spring.jackson.* settings or a Jackson2ObjectMapperBuilderCustomizer. By default Boot writes dates in ISO format and doesn't fail on an unknown field (FAIL_ON_UNKNOWN_PROPERTIES=false).

📖 Answer

spring:
  jackson:
    default-property-inclusion: non_null   # null fields are not written to the response
    time-zone: Asia/Tashkent
    serialization:
      write-dates-as-timestamps: false     # already the default in Boot
    deserialization:
      fail-on-unknown-properties: false    # Boot default

On dates: return Instant or OffsetDateTime from the API so the time zone is explicit: "2026-11-01T09:15:00Z". LocalDateTime has no zone, so the client can't tell what moment it means; use it only as a "wall clock" value (a class schedule, say). For things like birthdays, use LocalDate.

Unknown fields are ignored by default. That's convenient for an evolving API: if a client sends a new field, an older server doesn't break. But in JSON from an external payment system, a misspelled field name can silently disappear, so put @JsonIgnoreProperties(ignoreUnknown = false) on such DTOs.

Don't create an ObjectMapper with new; inject the bean Boot configured. Otherwise you lose the modules (JavaTimeModule) and settings, and in practice dates suddenly start coming out as numbers.