From e1961745ea5209c66990f76ba94bf8cd02b77387 Mon Sep 17 00:00:00 2001 From: Tatu Saloranta Date: Sun, 22 Jan 2012 16:03:47 -0800 Subject: Implement [JACKSON-764], programmatic way to set root name to use for root-wrapping --- .../jackson/databind/cfg/MapperConfigBase.java | 159 ++++++++++++++++++++- 1 file changed, 156 insertions(+), 3 deletions(-) (limited to 'src/main/java/com/fasterxml/jackson/databind/cfg/MapperConfigBase.java') diff --git a/src/main/java/com/fasterxml/jackson/databind/cfg/MapperConfigBase.java b/src/main/java/com/fasterxml/jackson/databind/cfg/MapperConfigBase.java index 2dfafd0d6..79add3375 100644 --- a/src/main/java/com/fasterxml/jackson/databind/cfg/MapperConfigBase.java +++ b/src/main/java/com/fasterxml/jackson/databind/cfg/MapperConfigBase.java @@ -1,9 +1,20 @@ package com.fasterxml.jackson.databind.cfg; +import java.text.DateFormat; import java.util.Map; +import com.fasterxml.jackson.annotation.JsonAutoDetect; +import com.fasterxml.jackson.annotation.PropertyAccessor; +import com.fasterxml.jackson.databind.AnnotationIntrospector; +import com.fasterxml.jackson.databind.BeanDescription; +import com.fasterxml.jackson.databind.HandlerInstantiator; +import com.fasterxml.jackson.databind.PropertyNamingStrategy; +import com.fasterxml.jackson.databind.introspect.ClassIntrospector; +import com.fasterxml.jackson.databind.introspect.VisibilityChecker; import com.fasterxml.jackson.databind.jsontype.SubtypeResolver; +import com.fasterxml.jackson.databind.jsontype.TypeResolverBuilder; import com.fasterxml.jackson.databind.type.ClassKey; +import com.fasterxml.jackson.databind.type.TypeFactory; public abstract class MapperConfigBase> @@ -28,6 +39,13 @@ public abstract class MapperConfigBase src, BaseSettings base) + { + super(base, src._mapperFeatures); + _mixInAnnotations = src._mixInAnnotations; + _subtypeResolver = src._subtypeResolver; + _rootName = src._rootName; } protected MapperConfigBase(MapperConfigBase src, int mapperFeatures) @@ -62,21 +90,142 @@ public abstract class MapperConfigBase src, SubtypeResolver str) { super(src); _mixInAnnotations = src._mixInAnnotations; _subtypeResolver = str; + _rootName = src._rootName; } - protected MapperConfigBase(MapperConfigBase src, BaseSettings base) - { - super(base, src._mapperFeatures); + protected MapperConfigBase(MapperConfigBase src, String rootName) { + super(src); _mixInAnnotations = src._mixInAnnotations; _subtypeResolver = src._subtypeResolver; + _rootName = rootName; } + + /* + /********************************************************** + /* Addition fluent factory methods, common to all sub-types + /********************************************************** + */ + + /** + * Method for constructing and returning a new instance with different + * {@link AnnotationIntrospector} to use (replacing old one). + *

+ * NOTE: make sure to register new instance with ObjectMapper + * if directly calling this method. + */ + public abstract T withAnnotationIntrospector(AnnotationIntrospector ai); + + /** + * Method for constructing and returning a new instance with additional + * {@link AnnotationIntrospector} appended (as the lowest priority one) + */ + public abstract T withAppendedAnnotationIntrospector(AnnotationIntrospector introspector); + + /** + * Method for constructing and returning a new instance with additional + * {@link AnnotationIntrospector} inserted (as the highest priority one) + */ + public abstract T withInsertedAnnotationIntrospector(AnnotationIntrospector introspector); + + /** + * Method for constructing and returning a new instance with different + * {@link ClassIntrospector} + * to use. + *

+ * NOTE: make sure to register new instance with ObjectMapper + * if directly calling this method. + */ + public abstract T withClassIntrospector(ClassIntrospector ci); + + /** + * Method for constructing and returning a new instance with different + * {@link DateFormat} + * to use. + *

+ * NOTE: make sure to register new instance with ObjectMapper + * if directly calling this method. + */ + public abstract T withDateFormat(DateFormat df); + + /** + * Method for constructing and returning a new instance with different + * {@link HandlerInstantiator} + * to use. + *

+ * NOTE: make sure to register new instance with ObjectMapper + * if directly calling this method. + */ + public abstract T withHandlerInstantiator(HandlerInstantiator hi); + + /** + * Method for constructing and returning a new instance with different + * {@link PropertyNamingStrategy} + * to use. + *

+ * NOTE: make sure to register new instance with ObjectMapper + * if directly calling this method. + */ + public abstract T withPropertyNamingStrategy(PropertyNamingStrategy strategy); + + /** + * Method for constructing and returning a new instance with different + * root name to use (none, if null). + *

+ * Note that when a root name is set to a non-Empty String, this will automatically force use + * of root element wrapping with given name. If empty String passed, will + * disable root name wrapping; and if null used, will instead use + * Feature to determine if to use wrapping, and annotation + * (or default name) for actual root name to use. + * + * @param rootName to use: if null, means "use default" (clear setting); + * if empty String ("") means that no root name wrapping is used; + * otherwise defines root name to use. + */ + public abstract T withRootName(String rootName); + + /** + * Method for constructing and returning a new instance with different + * {@link SubtypeResolver} + * to use. + *

+ * NOTE: make sure to register new instance with ObjectMapper + * if directly calling this method. + */ + public abstract T withSubtypeResolver(SubtypeResolver str); + + /** + * Method for constructing and returning a new instance with different + * {@link TypeFactory} + * to use. + */ + public abstract T withTypeFactory(TypeFactory typeFactory); + /** + * Method for constructing and returning a new instance with different + * {@link TypeResolverBuilder} to use. + */ + public abstract T withTypeResolverBuilder(TypeResolverBuilder trb); + + /** + * Method for constructing and returning a new instance with different + * {@link VisibilityChecker} + * to use. + */ + public abstract T withVisibilityChecker(VisibilityChecker vc); + + /** + * Method for constructing and returning a new instance with different + * minimal visibility level for specified property type + */ + public abstract T withVisibility(PropertyAccessor forMethod, JsonAutoDetect.Visibility visibility); + /* /********************************************************** /* Simple accessors @@ -93,6 +242,10 @@ public abstract class MapperConfigBase