类 Jackson2ObjectMapperBuilder
- java.lang.Object
- org.springframework.http.converter.json.Jackson2ObjectMapperBuilder
public class Jackson2ObjectMapperBuilder extends Object
A builder used to createObjectMapperinstances with a fluent API.It customizes Jackson's default properties with the following ones:
MapperFeature.DEFAULT_VIEW_INCLUSIONis disabledDeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIESis disabled
It also automatically registers the following well-known modules if they are detected on the classpath:
- jackson-datatype-jdk8: support for other Java 8 types like
Optional - jackson-datatype-jsr310: support for Java 8 Date & Time API types
- jackson-datatype-joda: support for Joda-Time types
- jackson-module-kotlin: support for Kotlin classes and data classes
Compatible with Jackson 2.6 and higher, as of Spring 4.3.
- 从以下版本开始:
- 4.1.1
- 作者:
- Sebastien Deleuze, Juergen Hoeller, Tadaya Tsuyukubo, Edd煤 Mel茅ndez
- 另请参阅:
build(),configure(ObjectMapper),Jackson2ObjectMapperFactoryBean
构造器概要
构造器 构造器 说明 Jackson2ObjectMapperBuilder()
方法概要
所有方法 静态方法 实例方法 具体方法 修饰符和类型 方法 说明 Jackson2ObjectMapperBuilderannotationIntrospector(AnnotationIntrospector annotationIntrospector)Set anAnnotationIntrospectorfor both serialization and deserialization.Jackson2ObjectMapperBuilderannotationIntrospector(Function<AnnotationIntrospector,AnnotationIntrospector> pairingFunction)Alternative toannotationIntrospector(AnnotationIntrospector)that allows combining with rather than replacing the currently set introspector, e.g. viaAnnotationIntrospector.pair(AnnotationIntrospector, AnnotationIntrospector).Jackson2ObjectMapperBuilderapplicationContext(ApplicationContext applicationContext)Set the SpringApplicationContextin order to autowire Jackson handlers (JsonSerializer,JsonDeserializer,KeyDeserializer,TypeResolverBuilderandTypeIdResolver).Jackson2ObjectMapperBuilderautoDetectFields(boolean autoDetectFields)Shortcut forMapperFeature.AUTO_DETECT_FIELDSoption.Jackson2ObjectMapperBuilderautoDetectGettersSetters(boolean autoDetectGettersSetters)<T extends ObjectMapper>
Tbuild()Build a newObjectMapperinstance.static Jackson2ObjectMapperBuildercbor()Obtain aJackson2ObjectMapperBuilderinstance in order to build a CBOR data formatObjectMapperinstance.voidconfigure(ObjectMapper objectMapper)Configure an existingObjectMapperinstance with this builder's settings.Jackson2ObjectMapperBuildercreateXmlMapper(boolean createXmlMapper)If set totrue, anXmlMapperwill be created using its default constructor.Jackson2ObjectMapperBuilderdateFormat(DateFormat dateFormat)Define the format for date/time with the givenDateFormat.Jackson2ObjectMapperBuilderdefaultTyping(TypeResolverBuilder<?> typeResolverBuilder)Specify aTypeResolverBuilderto use for Jackson's default typing.Jackson2ObjectMapperBuilderdefaultUseWrapper(boolean defaultUseWrapper)Define if a wrapper will be used for indexed (List, array) properties or not by default (only applies toXmlMapper).Jackson2ObjectMapperBuilderdefaultViewInclusion(boolean defaultViewInclusion)Shortcut forMapperFeature.DEFAULT_VIEW_INCLUSIONoption.Jackson2ObjectMapperBuilderdeserializerByType(Class<?> type, JsonDeserializer<?> deserializer)Configure a custom deserializer for the given type.Jackson2ObjectMapperBuilderdeserializers(JsonDeserializer<?>... deserializers)Configure custom deserializers.Jackson2ObjectMapperBuilderdeserializersByType(Map<Class<?>,JsonDeserializer<?>> deserializers)Configure custom deserializers for the given types.Jackson2ObjectMapperBuilderfactory(JsonFactory factory)Define theJsonFactoryto be used to create theObjectMapperinstance.Jackson2ObjectMapperBuilderfailOnEmptyBeans(boolean failOnEmptyBeans)Shortcut forSerializationFeature.FAIL_ON_EMPTY_BEANSoption.Jackson2ObjectMapperBuilderfailOnUnknownProperties(boolean failOnUnknownProperties)Shortcut forDeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIESoption.Jackson2ObjectMapperBuilderfeaturesToDisable(Object... featuresToDisable)Specify features to disable.Jackson2ObjectMapperBuilderfeaturesToEnable(Object... featuresToEnable)Specify features to enable.Jackson2ObjectMapperBuilderfilters(FilterProvider filters)Set the global filters to use in order to support@JsonFilterannotated POJO.Jackson2ObjectMapperBuilderfindModulesViaServiceLoader(boolean findModules)Set whether to let Jackson find available modules via the JDK ServiceLoader, based on META-INF metadata in the classpath.Jackson2ObjectMapperBuilderhandlerInstantiator(HandlerInstantiator handlerInstantiator)Customize the construction of Jackson handlers (JsonSerializer,JsonDeserializer,KeyDeserializer,TypeResolverBuilderandTypeIdResolver).Jackson2ObjectMapperBuilderindentOutput(boolean indentOutput)Shortcut forSerializationFeature.INDENT_OUTPUToption.static Jackson2ObjectMapperBuilderjson()Obtain aJackson2ObjectMapperBuilderinstance in order to build a regular JSONObjectMapperinstance.Jackson2ObjectMapperBuilderlocale(String localeString)Override the defaultLocaleto use for formatting.Jackson2ObjectMapperBuilderlocale(Locale locale)Override the defaultLocaleto use for formatting.Jackson2ObjectMapperBuildermixIn(Class<?> target, Class<?> mixinSource)Add mix-in annotations to use for augmenting specified class or interface.Jackson2ObjectMapperBuildermixIns(Map<Class<?>,Class<?>> mixIns)Add mix-in annotations to use for augmenting specified class or interface.Jackson2ObjectMapperBuildermoduleClassLoader(ClassLoader moduleClassLoader)Set the ClassLoader to use for loading Jackson extension modules.Jackson2ObjectMapperBuildermodules(Module... modules)Specify one or more modules to be registered with theObjectMapper.Jackson2ObjectMapperBuildermodules(List<Module> modules)Set a complete list of modules to be registered with theObjectMapper.Jackson2ObjectMapperBuildermodulesToInstall(Module... modules)Specify one or more modules to be registered with theObjectMapper.Jackson2ObjectMapperBuildermodulesToInstall(Class<? extends Module>... modules)Specify one or more modules by class to be registered with theObjectMapper.Jackson2ObjectMapperBuilderpropertyNamingStrategy(PropertyNamingStrategy propertyNamingStrategy)Specify aPropertyNamingStrategyto configure theObjectMapperwith.Jackson2ObjectMapperBuilderserializationInclusion(com.fasterxml.jackson.annotation.JsonInclude.Include serializationInclusion)Set a custom inclusion strategy for serialization.Jackson2ObjectMapperBuilderserializerByType(Class<?> type, JsonSerializer<?> serializer)Configure a custom serializer for the given type.Jackson2ObjectMapperBuilderserializers(JsonSerializer<?>... serializers)Configure custom serializers.Jackson2ObjectMapperBuilderserializersByType(Map<Class<?>,JsonSerializer<?>> serializers)Configure custom serializers for the given types.Jackson2ObjectMapperBuildersimpleDateFormat(String format)Define the date/time format with aSimpleDateFormat.static Jackson2ObjectMapperBuildersmile()Obtain aJackson2ObjectMapperBuilderinstance in order to build a Smile data formatObjectMapperinstance.Jackson2ObjectMapperBuildertimeZone(String timeZoneString)Override the defaultTimeZoneto use for formatting.Jackson2ObjectMapperBuildertimeZone(TimeZone timeZone)Override the defaultTimeZoneto use for formatting.Jackson2ObjectMapperBuildervisibility(com.fasterxml.jackson.annotation.PropertyAccessor accessor, com.fasterxml.jackson.annotation.JsonAutoDetect.Visibility visibility)Specify visibility to limit what kind of properties are auto-detected.static Jackson2ObjectMapperBuilderxml()Obtain aJackson2ObjectMapperBuilderinstance in order to build anXmlMapperinstance.
构造器详细资料
Jackson2ObjectMapperBuilder
public Jackson2ObjectMapperBuilder()
方法详细资料
createXmlMapper
public Jackson2ObjectMapperBuilder createXmlMapper(boolean createXmlMapper)
If set totrue, anXmlMapperwill be created using its default constructor. This is only applicable tobuild()calls, not toconfigure(com.fasterxml.jackson.databind.ObjectMapper)calls.
factory
public Jackson2ObjectMapperBuilder factory(JsonFactory factory)
Define theJsonFactoryto be used to create theObjectMapperinstance.- 从以下版本开始:
- 5.0
dateFormat
public Jackson2ObjectMapperBuilder dateFormat(DateFormat dateFormat)
Define the format for date/time with the givenDateFormat.Note: Setting this property makes the exposed
ObjectMappernon-thread-safe, according to Jackson's thread safety rules.
simpleDateFormat
public Jackson2ObjectMapperBuilder simpleDateFormat(String format)
Define the date/time format with aSimpleDateFormat.Note: Setting this property makes the exposed
ObjectMappernon-thread-safe, according to Jackson's thread safety rules.
locale
public Jackson2ObjectMapperBuilder locale(Locale locale)
Override the defaultLocaleto use for formatting. Default value used isLocale.getDefault().- 从以下版本开始:
- 4.1.5
locale
public Jackson2ObjectMapperBuilder locale(String localeString)
Override the defaultLocaleto use for formatting. Default value used isLocale.getDefault().- 参数:
localeString- the locale ID as a String representation- 从以下版本开始:
- 4.1.5
timeZone
public Jackson2ObjectMapperBuilder timeZone(TimeZone timeZone)
Override the defaultTimeZoneto use for formatting. Default value used is UTC (NOT local timezone).- 从以下版本开始:
- 4.1.5
timeZone
public Jackson2ObjectMapperBuilder timeZone(String timeZoneString)
Override the defaultTimeZoneto use for formatting. Default value used is UTC (NOT local timezone).- 参数:
timeZoneString- the zone ID as a String representation- 从以下版本开始:
- 4.1.5
annotationIntrospector
public Jackson2ObjectMapperBuilder annotationIntrospector(AnnotationIntrospector annotationIntrospector)
Set anAnnotationIntrospectorfor both serialization and deserialization.
annotationIntrospector
public Jackson2ObjectMapperBuilder annotationIntrospector(Function<AnnotationIntrospector,AnnotationIntrospector> pairingFunction)
Alternative toannotationIntrospector(AnnotationIntrospector)that allows combining with rather than replacing the currently set introspector, e.g. viaAnnotationIntrospector.pair(AnnotationIntrospector, AnnotationIntrospector).- 参数:
pairingFunction- a function to apply to the currently set introspector (possiblynull); the result of the function becomes the new introspector.- 从以下版本开始:
- 5.2.4
propertyNamingStrategy
public Jackson2ObjectMapperBuilder propertyNamingStrategy(PropertyNamingStrategy propertyNamingStrategy)
Specify aPropertyNamingStrategyto configure theObjectMapperwith.
defaultTyping
public Jackson2ObjectMapperBuilder defaultTyping(TypeResolverBuilder<?> typeResolverBuilder)
Specify aTypeResolverBuilderto use for Jackson's default typing.- 从以下版本开始:
- 4.2.2
serializationInclusion
public Jackson2ObjectMapperBuilder serializationInclusion(com.fasterxml.jackson.annotation.JsonInclude.Include serializationInclusion)
Set a custom inclusion strategy for serialization.- 另请参阅:
JsonInclude.Include
filters
public Jackson2ObjectMapperBuilder filters(FilterProvider filters)
Set the global filters to use in order to support@JsonFilterannotated POJO.- 从以下版本开始:
- 4.2
- 另请参阅:
MappingJacksonValue.setFilters(FilterProvider)
mixIn
public Jackson2ObjectMapperBuilder mixIn(Class<?> target, Class<?> mixinSource)
Add mix-in annotations to use for augmenting specified class or interface.- 参数:
target- class (or interface) whose annotations to effectively overridemixinSource- class (or interface) whose annotations are to be "added" to target's annotations as value- 从以下版本开始:
- 4.1.2
- 另请参阅:
ObjectMapper.addMixIn(Class, Class)
mixIns
public Jackson2ObjectMapperBuilder mixIns(Map<Class<?>,Class<?>> mixIns)
Add mix-in annotations to use for augmenting specified class or interface.- 参数:
mixIns- a Map of entries with target classes (or interface) whose annotations to effectively override as key and mix-in classes (or interface) whose annotations are to be "added" to target's annotations as value.- 从以下版本开始:
- 4.1.2
- 另请参阅:
ObjectMapper.addMixIn(Class, Class)
serializers
public Jackson2ObjectMapperBuilder serializers(JsonSerializer<?>... serializers)
Configure custom serializers. Each serializer is registered for the type returned byJsonSerializer.handledType(), which must not benull.
serializerByType
public Jackson2ObjectMapperBuilder serializerByType(Class<?> type, JsonSerializer<?> serializer)
Configure a custom serializer for the given type.- 从以下版本开始:
- 4.1.2
- 另请参阅:
serializers(JsonSerializer...)
serializersByType
public Jackson2ObjectMapperBuilder serializersByType(Map<Class<?>,JsonSerializer<?>> serializers)
Configure custom serializers for the given types.
deserializers
public Jackson2ObjectMapperBuilder deserializers(JsonDeserializer<?>... deserializers)
Configure custom deserializers. Each deserializer is registered for the type returned byJsonDeserializer.handledType(), which must not benull.- 从以下版本开始:
- 4.3
- 另请参阅:
deserializersByType(Map)
deserializerByType
public Jackson2ObjectMapperBuilder deserializerByType(Class<?> type, JsonDeserializer<?> deserializer)
Configure a custom deserializer for the given type.- 从以下版本开始:
- 4.1.2
deserializersByType
public Jackson2ObjectMapperBuilder deserializersByType(Map<Class<?>,JsonDeserializer<?>> deserializers)
Configure custom deserializers for the given types.
autoDetectFields
public Jackson2ObjectMapperBuilder autoDetectFields(boolean autoDetectFields)
Shortcut forMapperFeature.AUTO_DETECT_FIELDSoption.
autoDetectGettersSetters
public Jackson2ObjectMapperBuilder autoDetectGettersSetters(boolean autoDetectGettersSetters)
defaultViewInclusion
public Jackson2ObjectMapperBuilder defaultViewInclusion(boolean defaultViewInclusion)
Shortcut forMapperFeature.DEFAULT_VIEW_INCLUSIONoption.
failOnUnknownProperties
public Jackson2ObjectMapperBuilder failOnUnknownProperties(boolean failOnUnknownProperties)
Shortcut forDeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIESoption.
failOnEmptyBeans
public Jackson2ObjectMapperBuilder failOnEmptyBeans(boolean failOnEmptyBeans)
Shortcut forSerializationFeature.FAIL_ON_EMPTY_BEANSoption.
indentOutput
public Jackson2ObjectMapperBuilder indentOutput(boolean indentOutput)
Shortcut forSerializationFeature.INDENT_OUTPUToption.
defaultUseWrapper
public Jackson2ObjectMapperBuilder defaultUseWrapper(boolean defaultUseWrapper)
Define if a wrapper will be used for indexed (List, array) properties or not by default (only applies toXmlMapper).- 从以下版本开始:
- 4.3
visibility
public Jackson2ObjectMapperBuilder visibility(com.fasterxml.jackson.annotation.PropertyAccessor accessor, com.fasterxml.jackson.annotation.JsonAutoDetect.Visibility visibility)
Specify visibility to limit what kind of properties are auto-detected.- 从以下版本开始:
- 5.1
- 另请参阅:
PropertyAccessor,JsonAutoDetect.Visibility
featuresToEnable
public Jackson2ObjectMapperBuilder featuresToEnable(Object... featuresToEnable)
Specify features to enable.
featuresToDisable
public Jackson2ObjectMapperBuilder featuresToDisable(Object... featuresToDisable)
Specify features to disable.
modules
public Jackson2ObjectMapperBuilder modules(Module... modules)
Specify one or more modules to be registered with theObjectMapper. Multiple invocations are not additive, the last one defines the modules to register.Note: If this is set, no finding of modules is going to happen - not by Jackson, and not by Spring either (see
findModulesViaServiceLoader). As a consequence, specifying an empty list here will suppress any kind of module detection.Specify either this or
modulesToInstall(com.fasterxml.jackson.databind.Module...), not both.- 从以下版本开始:
- 4.1.5
- 另请参阅:
modules(List),Module
modules
public Jackson2ObjectMapperBuilder modules(List<Module> modules)
Set a complete list of modules to be registered with theObjectMapper. Multiple invocations are not additive, the last one defines the modules to register.Note: If this is set, no finding of modules is going to happen - not by Jackson, and not by Spring either (see
findModulesViaServiceLoader). As a consequence, specifying an empty list here will suppress any kind of module detection.Specify either this or
modulesToInstall(com.fasterxml.jackson.databind.Module...), not both.- 另请参阅:
modules(Module...),Module
modulesToInstall
public Jackson2ObjectMapperBuilder modulesToInstall(Module... modules)
Specify one or more modules to be registered with theObjectMapper. Multiple invocations are not additive, the last one defines the modules to register.Modules specified here will be registered after Spring's autodetection of JSR-310 and Joda-Time, or Jackson's finding of modules (see
findModulesViaServiceLoader), allowing to eventually override their configuration.Specify either this or
modules, not both.- 从以下版本开始:
- 4.1.5
- 另请参阅:
Module
modulesToInstall
public Jackson2ObjectMapperBuilder modulesToInstall(Class<? extends Module>... modules)
Specify one or more modules by class to be registered with theObjectMapper. Multiple invocations are not additive, the last one defines the modules to register.Modules specified here will be registered after Spring's autodetection of JSR-310 and Joda-Time, or Jackson's finding of modules (see
findModulesViaServiceLoader), allowing to eventually override their configuration.Specify either this or
modules, not both.
findModulesViaServiceLoader
public Jackson2ObjectMapperBuilder findModulesViaServiceLoader(boolean findModules)
Set whether to let Jackson find available modules via the JDK ServiceLoader, based on META-INF metadata in the classpath.If this mode is not set, Spring's Jackson2ObjectMapperBuilder itself will try to find the JSR-310 and Joda-Time support modules on the classpath - provided that Java 8 and Joda-Time themselves are available, respectively.
moduleClassLoader
public Jackson2ObjectMapperBuilder moduleClassLoader(ClassLoader moduleClassLoader)
Set the ClassLoader to use for loading Jackson extension modules.
handlerInstantiator
public Jackson2ObjectMapperBuilder handlerInstantiator(HandlerInstantiator handlerInstantiator)
Customize the construction of Jackson handlers (JsonSerializer,JsonDeserializer,KeyDeserializer,TypeResolverBuilderandTypeIdResolver).- 从以下版本开始:
- 4.1.3
- 另请参阅:
applicationContext(ApplicationContext)
applicationContext
public Jackson2ObjectMapperBuilder applicationContext(ApplicationContext applicationContext)
Set the SpringApplicationContextin order to autowire Jackson handlers (JsonSerializer,JsonDeserializer,KeyDeserializer,TypeResolverBuilderandTypeIdResolver).- 从以下版本开始:
- 4.1.3
- 另请参阅:
SpringHandlerInstantiator
build
public <T extends ObjectMapper> T build()
Build a newObjectMapperinstance.Each build operation produces an independent
ObjectMapperinstance. The builder's settings can get modified, with a subsequent build operation then producing a newObjectMapperbased on the most recent settings.- 返回:
- the newly built ObjectMapper
configure
public void configure(ObjectMapper objectMapper)
Configure an existingObjectMapperinstance with this builder's settings. This can be applied to any number ofObjectMappers.- 参数:
objectMapper- the ObjectMapper to configure
json
public static Jackson2ObjectMapperBuilder json()
Obtain aJackson2ObjectMapperBuilderinstance in order to build a regular JSONObjectMapperinstance.
xml
public static Jackson2ObjectMapperBuilder xml()
Obtain aJackson2ObjectMapperBuilderinstance in order to build anXmlMapperinstance.
smile
public static Jackson2ObjectMapperBuilder smile()
Obtain aJackson2ObjectMapperBuilderinstance in order to build a Smile data formatObjectMapperinstance.- 从以下版本开始:
- 5.0
cbor
public static Jackson2ObjectMapperBuilder cbor()
Obtain aJackson2ObjectMapperBuilderinstance in order to build a CBOR data formatObjectMapperinstance.- 从以下版本开始:
- 5.0