Class ObjectMapperBuilder
-
Method Summary
Modifier and TypeMethodDescriptionstatic tools.jackson.databind.json.JsonMapper.BuilderapplyLowercaseEnums(tools.jackson.databind.json.JsonMapper.Builder builder) 把「enum wire 值一律小寫」套用到任一
JsonMapper.Builder供兩個消費點共用同一規則:本 builder 的
withLowercaseEnums()(獨立 mapper), 以及LowercaseEnumJsonMapperCustomizer(Spring Boot 自動配置的 web mapper)。tools.jackson.databind.ObjectMapperbuild()構建 ObjectMapper 實例static ObjectMapperBuildercreate()創建新的 ObjectMapperBuilder 實例static ObjectMapperBuilder創建具有預設配置的 ObjectMapperBuilderstatic tools.jackson.databind.ObjectMapper快速創建具有預設配置的 ObjectMapper添加Byte序列化器withDateFormat(String pattern) withDateFormat(String pattern, ZoneId zoneId) 設置日期時間格式添加自Duration序列化器enum 的 wire 值一律小寫withModule(tools.jackson.databind.JacksonModule customModule) 註冊自定義模組withSerializationFeature(tools.jackson.databind.SerializationFeature feature, boolean state) 添加序列化功能配置添加日期時間序列化器
-
Method Details
-
create
創建新的 ObjectMapperBuilder 實例 -
createWithDefaults
創建具有預設配置的 ObjectMapperBuilder
Jackson 3.x 已內建 Java 8 日期時間類型支援 (LocalDate、LocalDateTime、LocalTime 等)
-
withDateFormat
設置日期時間格式 -
withDateFormat
-
withZonedDateTime
添加日期時間序列化器 -
withInstant
-
withDuration
添加自Duration序列化器 -
withBytes
添加Byte序列化器 -
withSerializationFeature
public ObjectMapperBuilder withSerializationFeature(tools.jackson.databind.SerializationFeature feature, boolean state) 添加序列化功能配置 -
withLowercaseEnums
enum 的 wire 值一律小寫
啟用後
OrderStatus.PENDING_CONFIRMATION序列化為"pending_confirmation", 反序列化則容忍大小寫("PENDING_CONFIRMATION"亦可讀入)。enum 本身不需再逐個 標註@JsonValue/@JsonCreator。預設關閉:既有下游可能已將
UPPER_SNAKE常數名直接當成 wire 值,開啟即變更 其 API 契約。遷移時機由各應用自行決定,框架不代為決定。不影響 DB 持久化——
@Enumerated(EnumType.STRING)仍以name()存大寫。查詢參數/路徑變數走 Spring ConversionService、不經 Jackson,需另行註冊
StringToEnumConverterFactory才會一致。 -
withModule
註冊自定義模組 -
build
public tools.jackson.databind.ObjectMapper build()構建 ObjectMapper 實例 -
applyLowercaseEnums
public static tools.jackson.databind.json.JsonMapper.Builder applyLowercaseEnums(tools.jackson.databind.json.JsonMapper.Builder builder) 把「enum wire 值一律小寫」套用到任一
JsonMapper.Builder供兩個消費點共用同一規則:本 builder 的
withLowercaseEnums()(獨立 mapper), 以及LowercaseEnumJsonMapperCustomizer(Spring Boot 自動配置的 web mapper)。- Parameters:
builder- 待套用的 builder- Returns:
- 同一個 builder,供串接
-
defaultObjectMapper
public static tools.jackson.databind.ObjectMapper defaultObjectMapper()快速創建具有預設配置的 ObjectMapper
-