Skip to content

Commit

Permalink
More work on #2800, wiring mostly in place
Browse files Browse the repository at this point in the history
  • Loading branch information
cowtowncoder committed Aug 18, 2020
1 parent 2ad1d95 commit 2e494a9
Show file tree
Hide file tree
Showing 10 changed files with 117 additions and 37 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,6 @@
import com.fasterxml.jackson.core.Version;
import com.fasterxml.jackson.core.Versioned;

import com.fasterxml.jackson.databind.JsonDeserializer;
import com.fasterxml.jackson.databind.JsonSerializer;
import com.fasterxml.jackson.databind.annotation.JsonPOJOBuilder;
import com.fasterxml.jackson.databind.annotation.JsonSerialize;
import com.fasterxml.jackson.databind.cfg.MapperConfig;
Expand Down
17 changes: 15 additions & 2 deletions src/main/java/com/fasterxml/jackson/databind/ObjectMapper.java
Original file line number Diff line number Diff line change
Expand Up @@ -366,7 +366,9 @@ public boolean useForType(JavaType t)
null, // to indicate "use Jackson default TimeZone" (UTC since Jackson 2.7)
Base64Variants.getDefaultVariant(),
// Only for 2.x; 3.x will use more restrictive default
LaissezFaireSubTypeValidator.instance
LaissezFaireSubTypeValidator.instance,
// Since 2.12:
new DefaultAccessorNamingStrategy.Provider()
);

/*
Expand Down Expand Up @@ -1648,7 +1650,7 @@ public ObjectMapper setAnnotationIntrospectors(AnnotationIntrospector serializer
_deserializationConfig = _deserializationConfig.with(deserializerAI);
return this;
}

/**
* Method for setting custom property naming strategy to use.
*/
Expand All @@ -1666,6 +1668,17 @@ public PropertyNamingStrategy getPropertyNamingStrategy() {
return _serializationConfig.getPropertyNamingStrategy();
}

/**
* Method for setting custom accessor naming strategy to use.
*
* @since 2.12
*/
public ObjectMapper setAccessorNaming(AccessorNamingStrategy.Provider s) {
_serializationConfig = _serializationConfig.with(s);
_deserializationConfig = _deserializationConfig.with(s);
return this;
}

/**
* Method for specifying {@link PrettyPrinter} to use when "default pretty-printing"
* is enabled (by enabling {@link SerializationFeature#INDENT_OUTPUT})
Expand Down
75 changes: 51 additions & 24 deletions src/main/java/com/fasterxml/jackson/databind/cfg/BaseSettings.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,12 @@
import java.util.TimeZone;

import com.fasterxml.jackson.core.Base64Variant;

import com.fasterxml.jackson.databind.*;
import com.fasterxml.jackson.databind.introspect.AccessorNamingStrategy;
import com.fasterxml.jackson.databind.introspect.AnnotationIntrospectorPair;
import com.fasterxml.jackson.databind.introspect.ClassIntrospector;
import com.fasterxml.jackson.databind.introspect.DefaultAccessorNamingStrategy;
import com.fasterxml.jackson.databind.jsontype.PolymorphicTypeValidator;
import com.fasterxml.jackson.databind.jsontype.TypeResolverBuilder;
import com.fasterxml.jackson.databind.type.TypeFactory;
Expand Down Expand Up @@ -39,7 +42,14 @@ public final class BaseSettings
/* Configuration settings; introspection, related
/**********************************************************
*/


/**
* Specific factory used for creating {@link JavaType} instances;
* needed to allow modules to add more custom type handling
* (mostly to support types of non-Java JVM languages)
*/
protected final TypeFactory _typeFactory;

/**
* Introspector used to figure out Bean properties needed for bean serialization
* and deserialization. Overridable so that it is possible to change low-level
Expand All @@ -58,15 +68,15 @@ public final class BaseSettings
protected final PropertyNamingStrategy _propertyNamingStrategy;

/**
* Specific factory used for creating {@link JavaType} instances;
* needed to allow modules to add more custom type handling
* (mostly to support types of non-Java JVM languages)
* Provider for creating {@link AccessorNamingStrategy} instances to use
*
* @since 2.12
*/
protected final TypeFactory _typeFactory;
protected final AccessorNamingStrategy.Provider _accessorNaming;

/*
/**********************************************************
/* Configuration settings; poly type resolution
/* Configuration settings; polymorphic type resolution
/**********************************************************
*/

Expand Down Expand Up @@ -140,13 +150,13 @@ public final class BaseSettings
*/

/**
* @since 2.10
* @since 2.12
*/
public BaseSettings(ClassIntrospector ci, AnnotationIntrospector ai,
PropertyNamingStrategy pns, TypeFactory tf,
TypeResolverBuilder<?> typer, DateFormat dateFormat, HandlerInstantiator hi,
Locale locale, TimeZone tz, Base64Variant defaultBase64,
PolymorphicTypeValidator ptv)
PolymorphicTypeValidator ptv, AccessorNamingStrategy.Provider accNaming)
{
_classIntrospector = ci;
_annotationIntrospector = ai;
Expand All @@ -159,15 +169,18 @@ public BaseSettings(ClassIntrospector ci, AnnotationIntrospector ai,
_timeZone = tz;
_defaultBase64 = defaultBase64;
_typeValidator = ptv;
_accessorNaming = accNaming;
}

@Deprecated // since 2.10
@Deprecated // since 2.12
public BaseSettings(ClassIntrospector ci, AnnotationIntrospector ai,
PropertyNamingStrategy pns, TypeFactory tf,
TypeResolverBuilder<?> typer, DateFormat dateFormat, HandlerInstantiator hi,
Locale locale, TimeZone tz, Base64Variant defaultBase64)
Locale locale, TimeZone tz, Base64Variant defaultBase64,
PolymorphicTypeValidator ptv)
{
this(ci, ai, pns, tf, typer, dateFormat, hi, locale, tz, defaultBase64, null);
this(ci, ai, pns, tf, typer, dateFormat, hi, locale, tz, defaultBase64, ptv,
new DefaultAccessorNamingStrategy.Provider());
}

/**
Expand All @@ -187,8 +200,8 @@ public BaseSettings copy() {
_locale,
_timeZone,
_defaultBase64,
_typeValidator);

_typeValidator,
_accessorNaming);
}

/*
Expand All @@ -203,7 +216,7 @@ public BaseSettings withClassIntrospector(ClassIntrospector ci) {
}
return new BaseSettings(ci, _annotationIntrospector, _propertyNamingStrategy, _typeFactory,
_typeResolverBuilder, _dateFormat, _handlerInstantiator, _locale,
_timeZone, _defaultBase64, _typeValidator);
_timeZone, _defaultBase64, _typeValidator, _accessorNaming);
}

public BaseSettings withAnnotationIntrospector(AnnotationIntrospector ai) {
Expand All @@ -212,7 +225,7 @@ public BaseSettings withAnnotationIntrospector(AnnotationIntrospector ai) {
}
return new BaseSettings(_classIntrospector, ai, _propertyNamingStrategy, _typeFactory,
_typeResolverBuilder, _dateFormat, _handlerInstantiator, _locale,
_timeZone, _defaultBase64, _typeValidator);
_timeZone, _defaultBase64, _typeValidator, _accessorNaming);
}

public BaseSettings withInsertedAnnotationIntrospector(AnnotationIntrospector ai) {
Expand All @@ -239,7 +252,17 @@ public BaseSettings withPropertyNamingStrategy(PropertyNamingStrategy pns) {
}
return new BaseSettings(_classIntrospector, _annotationIntrospector, pns, _typeFactory,
_typeResolverBuilder, _dateFormat, _handlerInstantiator, _locale,
_timeZone, _defaultBase64, _typeValidator);
_timeZone, _defaultBase64, _typeValidator, _accessorNaming);
}

// @since 2.12
public BaseSettings withAccessorNaming(AccessorNamingStrategy.Provider p) {
if (_accessorNaming == p) {
return this;
}
return new BaseSettings(_classIntrospector, _annotationIntrospector, _propertyNamingStrategy, _typeFactory,
_typeResolverBuilder, _dateFormat, _handlerInstantiator, _locale,
_timeZone, _defaultBase64, _typeValidator, _accessorNaming);
}

public BaseSettings withTypeFactory(TypeFactory tf) {
Expand All @@ -248,7 +271,7 @@ public BaseSettings withTypeFactory(TypeFactory tf) {
}
return new BaseSettings(_classIntrospector, _annotationIntrospector, _propertyNamingStrategy, tf,
_typeResolverBuilder, _dateFormat, _handlerInstantiator, _locale,
_timeZone, _defaultBase64, _typeValidator);
_timeZone, _defaultBase64, _typeValidator, _accessorNaming);
}

public BaseSettings withTypeResolverBuilder(TypeResolverBuilder<?> typer) {
Expand All @@ -257,7 +280,7 @@ public BaseSettings withTypeResolverBuilder(TypeResolverBuilder<?> typer) {
}
return new BaseSettings(_classIntrospector, _annotationIntrospector, _propertyNamingStrategy, _typeFactory,
typer, _dateFormat, _handlerInstantiator, _locale,
_timeZone, _defaultBase64, _typeValidator);
_timeZone, _defaultBase64, _typeValidator, _accessorNaming);
}

public BaseSettings withDateFormat(DateFormat df) {
Expand All @@ -271,7 +294,7 @@ public BaseSettings withDateFormat(DateFormat df) {
}
return new BaseSettings(_classIntrospector, _annotationIntrospector, _propertyNamingStrategy, _typeFactory,
_typeResolverBuilder, df, _handlerInstantiator, _locale,
_timeZone, _defaultBase64, _typeValidator);
_timeZone, _defaultBase64, _typeValidator, _accessorNaming);
}

public BaseSettings withHandlerInstantiator(HandlerInstantiator hi) {
Expand All @@ -280,7 +303,7 @@ public BaseSettings withHandlerInstantiator(HandlerInstantiator hi) {
}
return new BaseSettings(_classIntrospector, _annotationIntrospector, _propertyNamingStrategy, _typeFactory,
_typeResolverBuilder, _dateFormat, hi, _locale,
_timeZone, _defaultBase64, _typeValidator);
_timeZone, _defaultBase64, _typeValidator, _accessorNaming);
}

public BaseSettings with(Locale l) {
Expand All @@ -289,7 +312,7 @@ public BaseSettings with(Locale l) {
}
return new BaseSettings(_classIntrospector, _annotationIntrospector, _propertyNamingStrategy, _typeFactory,
_typeResolverBuilder, _dateFormat, _handlerInstantiator, l,
_timeZone, _defaultBase64, _typeValidator);
_timeZone, _defaultBase64, _typeValidator, _accessorNaming);
}

/**
Expand All @@ -310,7 +333,7 @@ public BaseSettings with(TimeZone tz)
return new BaseSettings(_classIntrospector, _annotationIntrospector,
_propertyNamingStrategy, _typeFactory,
_typeResolverBuilder, df, _handlerInstantiator, _locale,
tz, _defaultBase64, _typeValidator);
tz, _defaultBase64, _typeValidator, _accessorNaming);
}

/**
Expand All @@ -323,7 +346,7 @@ public BaseSettings with(Base64Variant base64) {
return new BaseSettings(_classIntrospector, _annotationIntrospector,
_propertyNamingStrategy, _typeFactory,
_typeResolverBuilder, _dateFormat, _handlerInstantiator, _locale,
_timeZone, base64, _typeValidator);
_timeZone, base64, _typeValidator, _accessorNaming);
}

/**
Expand All @@ -336,7 +359,7 @@ public BaseSettings with(PolymorphicTypeValidator v) {
return new BaseSettings(_classIntrospector, _annotationIntrospector,
_propertyNamingStrategy, _typeFactory,
_typeResolverBuilder, _dateFormat, _handlerInstantiator, _locale,
_timeZone, _defaultBase64, v);
_timeZone, _defaultBase64, v, _accessorNaming);
}

/*
Expand All @@ -357,6 +380,10 @@ public PropertyNamingStrategy getPropertyNamingStrategy() {
return _propertyNamingStrategy;
}

public AccessorNamingStrategy.Provider getAccessorNaming() {
return _accessorNaming;
}

public TypeFactory getTypeFactory() {
return _typeFactory;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@
import com.fasterxml.jackson.databind.*;
import com.fasterxml.jackson.databind.ObjectMapper.DefaultTyping;
import com.fasterxml.jackson.databind.deser.*;
import com.fasterxml.jackson.databind.introspect.AccessorNamingStrategy;
import com.fasterxml.jackson.databind.introspect.DefaultAccessorNamingStrategy;
import com.fasterxml.jackson.databind.introspect.VisibilityChecker;
import com.fasterxml.jackson.databind.jsontype.NamedType;
import com.fasterxml.jackson.databind.jsontype.PolymorphicTypeValidator;
Expand Down Expand Up @@ -373,17 +375,45 @@ public B visibility(PropertyAccessor forMethod, JsonAutoDetect.Visibility visibi
* id resolvers), given a class.
*
* @param hi Instantiator to use; if null, use the default implementation
*
* @return Builder instance itself to allow chaining
*/
public B handlerInstantiator(HandlerInstantiator hi) {
_mapper.setHandlerInstantiator(hi);
return _this();
}

/**
* Method for configuring {@link PropertyNamingStrategy} to use for adapting
* POJO property names (internal) into content property names (external)
*
* @param s Strategy instance to use; if null, use the default implementation
*
* @return Builder instance itself to allow chaining
*/
public B propertyNamingStrategy(PropertyNamingStrategy s) {
_mapper.setPropertyNamingStrategy(s);
return _this();
}

/**
* Method for configuring {@link AccessorNamingStrategy} to use for auto-detecting
* accessor ("getter") and mutator ("setter") methods based on naming of methods.
*
* @param s Strategy instance to use; if null, use the default implementation
*
* @return Builder instance itself to allow chaining
*
* @since 2.12
*/
public B accessorNaming(AccessorNamingStrategy.Provider s) {
if (s == null) {
s = new DefaultAccessorNamingStrategy.Provider();
}
_mapper.setAccessorNaming(s);
return _this();
}

/*
/**********************************************************************
/* Changing factories, serialization
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
import com.fasterxml.jackson.core.io.SerializedString;
import com.fasterxml.jackson.core.type.TypeReference;
import com.fasterxml.jackson.databind.*;
import com.fasterxml.jackson.databind.introspect.AccessorNamingStrategy;
import com.fasterxml.jackson.databind.introspect.Annotated;
import com.fasterxml.jackson.databind.introspect.AnnotatedClass;
import com.fasterxml.jackson.databind.introspect.ClassIntrospector;
Expand Down Expand Up @@ -246,6 +247,11 @@ public final PropertyNamingStrategy getPropertyNamingStrategy() {
return _base.getPropertyNamingStrategy();
}

// @since 2.12
public final AccessorNamingStrategy.Provider getAccessorNaming() {
return _base.getAccessorNaming();
}

public final HandlerInstantiator getHandlerInstantiator() {
return _base.getHandlerInstantiator();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
import com.fasterxml.jackson.databind.*;
import com.fasterxml.jackson.databind.introspect.ClassIntrospector;
import com.fasterxml.jackson.databind.introspect.ClassIntrospector.MixInResolver;
import com.fasterxml.jackson.databind.introspect.AccessorNamingStrategy;
import com.fasterxml.jackson.databind.introspect.AnnotatedClass;
import com.fasterxml.jackson.databind.introspect.SimpleMixInResolver;
import com.fasterxml.jackson.databind.introspect.VisibilityChecker;
Expand Down Expand Up @@ -457,6 +458,17 @@ public final T with(PropertyNamingStrategy pns) {
return _withBase(_base.withPropertyNamingStrategy(pns));
}

/**
* Method for constructing and returning a new instance with different
* {@link PropertyNamingStrategy}
* to use.
*
* @since 2.12
*/
public final T with(AccessorNamingStrategy.Provider p) {
return _withBase(_base.withAccessorNaming(p));
}

/**
* Method for constructing and returning a new instance with different
* {@link HandlerInstantiator}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ private static class JavaUtilCollectionsConverter implements Converter<Object,Ob

private final int _kind;

private JavaUtilCollectionsConverter(int kind, JavaType inputType) {
JavaUtilCollectionsConverter(int kind, JavaType inputType) {
_inputType = inputType;
_kind = kind;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@
import com.fasterxml.jackson.databind.annotation.JacksonStdImpl;
import com.fasterxml.jackson.databind.deser.*;
import com.fasterxml.jackson.databind.deser.impl.ReadableObjectId.Referring;
import com.fasterxml.jackson.databind.deser.std.ContainerDeserializerBase;
import com.fasterxml.jackson.databind.jsontype.TypeDeserializer;
import com.fasterxml.jackson.databind.type.LogicalType;
import com.fasterxml.jackson.databind.util.ClassUtil;
Expand Down
Loading

0 comments on commit 2e494a9

Please sign in to comment.