Skip to content

Commit

Permalink
Merge branch '2.12'
Browse files Browse the repository at this point in the history
  • Loading branch information
cowtowncoder committed Aug 18, 2020
2 parents 818a44f + 2e494a9 commit a64e1bf
Show file tree
Hide file tree
Showing 56 changed files with 165 additions and 147 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
57 changes: 37 additions & 20 deletions src/main/java/com/fasterxml/jackson/databind/cfg/BaseSettings.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
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.jsontype.PolymorphicTypeValidator;
import com.fasterxml.jackson.databind.jsontype.TypeResolverBuilder;
Expand All @@ -30,9 +31,9 @@ public final class BaseSettings
private static final TimeZone DEFAULT_TIMEZONE = TimeZone.getTimeZone("UTC");

/*
/**********************************************************
/**********************************************************************
/* Configuration settings; introspection, related
/**********************************************************
/**********************************************************************
*/

/**
Expand All @@ -45,10 +46,15 @@ public final class BaseSettings
*/
protected final PropertyNamingStrategy _propertyNamingStrategy;

/**
* Provider for creating {@link AccessorNamingStrategy} instances to use
*/
protected final AccessorNamingStrategy.Provider _accessorNaming;

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

/**
Expand Down Expand Up @@ -121,14 +127,16 @@ public final class BaseSettings
/**********************************************************
*/

public BaseSettings(AnnotationIntrospector ai, PropertyNamingStrategy pns,
public BaseSettings(AnnotationIntrospector ai,
PropertyNamingStrategy pns, AccessorNamingStrategy.Provider accNaming,
TypeResolverBuilder<?> defaultTyper, PolymorphicTypeValidator ptv,
DateFormat dateFormat, HandlerInstantiator hi,
Locale locale, TimeZone tz, Base64Variant defaultBase64,
JsonNodeFactory nodeFactory)
{
_annotationIntrospector = ai;
_propertyNamingStrategy = pns;
_accessorNaming = accNaming;
_defaultTyper = defaultTyper;
_typeValidator = ptv;
_dateFormat = dateFormat;
Expand All @@ -149,7 +157,7 @@ public BaseSettings withAnnotationIntrospector(AnnotationIntrospector ai) {
if (_annotationIntrospector == ai) {
return this;
}
return new BaseSettings(ai, _propertyNamingStrategy,
return new BaseSettings(ai, _propertyNamingStrategy, _accessorNaming,
_defaultTyper, _typeValidator, _dateFormat, _handlerInstantiator, _locale,
_timeZone, _defaultBase64, _nodeFactory);
}
Expand All @@ -166,7 +174,16 @@ public BaseSettings with(PropertyNamingStrategy pns) {
if (_propertyNamingStrategy == pns) {
return this;
}
return new BaseSettings(_annotationIntrospector, pns,
return new BaseSettings(_annotationIntrospector, pns, _accessorNaming,
_defaultTyper, _typeValidator, _dateFormat, _handlerInstantiator, _locale,
_timeZone, _defaultBase64, _nodeFactory);
}

public BaseSettings with(AccessorNamingStrategy.Provider p) {
if (_accessorNaming == p) {
return this;
}
return new BaseSettings(_annotationIntrospector, _propertyNamingStrategy, p,
_defaultTyper, _typeValidator, _dateFormat, _handlerInstantiator, _locale,
_timeZone, _defaultBase64, _nodeFactory);
}
Expand All @@ -175,7 +192,7 @@ public BaseSettings with(TypeResolverBuilder<?> typer) {
if (_defaultTyper == typer) {
return this;
}
return new BaseSettings(_annotationIntrospector, _propertyNamingStrategy,
return new BaseSettings(_annotationIntrospector, _propertyNamingStrategy, _accessorNaming,
typer, _typeValidator, _dateFormat, _handlerInstantiator, _locale,
_timeZone, _defaultBase64, _nodeFactory);
}
Expand All @@ -184,7 +201,7 @@ public BaseSettings with(PolymorphicTypeValidator ptv) {
if (_typeValidator == ptv) {
return this;
}
return new BaseSettings(_annotationIntrospector, _propertyNamingStrategy,
return new BaseSettings(_annotationIntrospector, _propertyNamingStrategy, _accessorNaming,
_defaultTyper, ptv, _dateFormat, _handlerInstantiator, _locale,
_timeZone, _defaultBase64, _nodeFactory);
}
Expand All @@ -198,7 +215,7 @@ public BaseSettings with(DateFormat df) {
if ((df != null) && hasExplicitTimeZone()) {
df = _force(df, _timeZone);
}
return new BaseSettings(_annotationIntrospector, _propertyNamingStrategy,
return new BaseSettings(_annotationIntrospector, _propertyNamingStrategy, _accessorNaming,
_defaultTyper, _typeValidator, df, _handlerInstantiator, _locale,
_timeZone, _defaultBase64, _nodeFactory);
}
Expand All @@ -207,7 +224,7 @@ public BaseSettings with(HandlerInstantiator hi) {
if (_handlerInstantiator == hi) {
return this;
}
return new BaseSettings(_annotationIntrospector, _propertyNamingStrategy,
return new BaseSettings(_annotationIntrospector, _propertyNamingStrategy, _accessorNaming,
_defaultTyper, _typeValidator, _dateFormat, hi, _locale,
_timeZone, _defaultBase64, _nodeFactory);
}
Expand All @@ -216,7 +233,7 @@ public BaseSettings with(Locale l) {
if (_locale == l) {
return this;
}
return new BaseSettings(_annotationIntrospector, _propertyNamingStrategy,
return new BaseSettings(_annotationIntrospector, _propertyNamingStrategy, _accessorNaming,
_defaultTyper, _typeValidator, _dateFormat, _handlerInstantiator, l,
_timeZone, _defaultBase64, _nodeFactory);
}
Expand All @@ -234,10 +251,8 @@ public BaseSettings with(TimeZone tz)
if (tz == _timeZone) {
return this;
}

DateFormat df = _force(_dateFormat, tz);
return new BaseSettings(_annotationIntrospector,
_propertyNamingStrategy,
return new BaseSettings(_annotationIntrospector, _propertyNamingStrategy, _accessorNaming,
_defaultTyper, _typeValidator, df, _handlerInstantiator, _locale,
tz, _defaultBase64, _nodeFactory);
}
Expand All @@ -246,8 +261,7 @@ public BaseSettings with(Base64Variant base64) {
if (base64 == _defaultBase64) {
return this;
}
return new BaseSettings(_annotationIntrospector,
_propertyNamingStrategy,
return new BaseSettings(_annotationIntrospector, _propertyNamingStrategy, _accessorNaming,
_defaultTyper, _typeValidator, _dateFormat, _handlerInstantiator, _locale,
_timeZone, base64, _nodeFactory);
}
Expand All @@ -256,8 +270,7 @@ public BaseSettings with(JsonNodeFactory nodeFactory) {
if (nodeFactory == _nodeFactory) {
return this;
}
return new BaseSettings(_annotationIntrospector,
_propertyNamingStrategy,
return new BaseSettings(_annotationIntrospector, _propertyNamingStrategy, _accessorNaming,
_defaultTyper, _typeValidator, _dateFormat, _handlerInstantiator, _locale,
_timeZone, _defaultBase64, nodeFactory);
}
Expand All @@ -276,6 +289,10 @@ public PropertyNamingStrategy getPropertyNamingStrategy() {
return _propertyNamingStrategy;
}

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

public TypeResolverBuilder<?> getDefaultTyper() {
return _defaultTyper;
}
Expand Down
48 changes: 35 additions & 13 deletions src/main/java/com/fasterxml/jackson/databind/cfg/MapperBuilder.java
Original file line number Diff line number Diff line change
Expand Up @@ -10,23 +10,15 @@
import com.fasterxml.jackson.annotation.JsonInclude;
import com.fasterxml.jackson.annotation.JsonSetter;
import com.fasterxml.jackson.annotation.JsonTypeInfo;

import com.fasterxml.jackson.core.*;
import com.fasterxml.jackson.core.util.DefaultPrettyPrinter;
import com.fasterxml.jackson.core.util.Snapshottable;

import com.fasterxml.jackson.databind.*;
import com.fasterxml.jackson.databind.deser.*;
import com.fasterxml.jackson.databind.introspect.BasicClassIntrospector;
import com.fasterxml.jackson.databind.introspect.ClassIntrospector;
import com.fasterxml.jackson.databind.introspect.JacksonAnnotationIntrospector;
import com.fasterxml.jackson.databind.introspect.MixInResolver;
import com.fasterxml.jackson.databind.introspect.MixInHandler;
import com.fasterxml.jackson.databind.introspect.VisibilityChecker;
import com.fasterxml.jackson.databind.jsontype.NamedType;
import com.fasterxml.jackson.databind.jsontype.DefaultBaseTypeLimitingValidator;
import com.fasterxml.jackson.databind.jsontype.PolymorphicTypeValidator;
import com.fasterxml.jackson.databind.jsontype.SubtypeResolver;
import com.fasterxml.jackson.databind.jsontype.TypeResolverBuilder;
import com.fasterxml.jackson.databind.jsontype.TypeResolverProvider;
import com.fasterxml.jackson.databind.introspect.*;
import com.fasterxml.jackson.databind.jsontype.*;
import com.fasterxml.jackson.databind.jsontype.impl.DefaultTypeResolverBuilder;
import com.fasterxml.jackson.databind.jsontype.impl.StdSubtypeResolver;
import com.fasterxml.jackson.databind.node.JsonNodeFactory;
Expand Down Expand Up @@ -58,9 +50,11 @@ public abstract class MapperBuilder<M extends ObjectMapper,

protected final static PolymorphicTypeValidator DEFAULT_TYPE_VALIDATOR = new DefaultBaseTypeLimitingValidator();

protected final static AccessorNamingStrategy.Provider DEFAULT_ACCESSOR_NAMING = new DefaultAccessorNamingStrategy.Provider();

protected final static BaseSettings DEFAULT_BASE_SETTINGS = new BaseSettings(
DEFAULT_ANNOTATION_INTROSPECTOR,
null,
null, DEFAULT_ACCESSOR_NAMING,
null, // no default typing, by default
DEFAULT_TYPE_VALIDATOR, // and polymorphic type by class won't pass either
StdDateFormat.instance, null,
Expand Down Expand Up @@ -1138,17 +1132,45 @@ public B polymorphicTypeValidator(PolymorphicTypeValidator ptv) {
* 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) {
_baseSettings = _baseSettings.with(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) {
_baseSettings = _baseSettings.with(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();
}
_baseSettings = _baseSettings.with(s);
return _this();
}

/*
/**********************************************************************
/* Changing factories, serialization
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -190,6 +190,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 @@ -4,8 +4,10 @@
import java.util.*;

import com.fasterxml.jackson.annotation.*;

import com.fasterxml.jackson.core.Base64Variant;
import com.fasterxml.jackson.core.type.TypeReference;

import com.fasterxml.jackson.databind.*;
import com.fasterxml.jackson.databind.introspect.*;
import com.fasterxml.jackson.databind.jsontype.SubtypeResolver;
Expand Down Expand Up @@ -277,7 +279,7 @@ public final T with(TypeResolverBuilder<?> trb) {

/**
* Fluent factory method that will construct a new instance with
* specified {@link JsonNodeFactory}
* specified {@link JsonNodeFactory}.
*/
public final T with(JsonNodeFactory f) {
return _withBase(_base.with(f));
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
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,7 @@ private static boolean isGroovyMetaClassGetter(AnnotatedMethod am) {
/**
* Provider for {@link DefaultAccessorNamingStrategy}.
*/
protected static class Provider
public final static class Provider
extends AccessorNamingStrategy.Provider
implements java.io.Serializable
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,6 @@
*/
public class POJOPropertiesCollector
{
// !!! TEMPORARY
protected final static AccessorNamingStrategy.Provider NAMING_PROVIDER
= new DefaultAccessorNamingStrategy.Provider();

/*
/**********************************************************************
/* Configuration
Expand Down Expand Up @@ -150,7 +146,7 @@ protected POJOPropertiesCollector(MapperConfig<?> config, boolean forSerializati
_visibilityChecker = _config.getDefaultVisibilityChecker(type.getRawClass(),
classDef);

_accessorNaming = NAMING_PROVIDER.forPOJO(_config, classDef, mutatorPrefix);
_accessorNaming = config.getAccessorNaming().forPOJO(_config, classDef, mutatorPrefix);
}

/*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2179,11 +2179,11 @@ private final void assignNativeIds(int index, Object objectId, Object typeId)
}
}

private Object findObjectId(int index) {
public Object findObjectId(int index) {
return (_nativeIds == null) ? null : _nativeIds.get(_objectIdIndex(index));
}

private Object findTypeId(int index) {
public Object findTypeId(int index) {
return (_nativeIds == null) ? null : _nativeIds.get(_typeIdIndex(index));
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@

import com.fasterxml.jackson.core.*;

import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.databind.deser.std.StdScalarDeserializer;
import com.fasterxml.jackson.databind.ser.std.StdScalarSerializer;
import com.fasterxml.jackson.databind.type.TypeFactory;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
import com.fasterxml.jackson.core.io.SerializedString;
import com.fasterxml.jackson.core.json.JsonFactory;
import com.fasterxml.jackson.core.json.JsonWriteFeature;
import com.fasterxml.jackson.databind.ObjectMapper;

public class MapperViaParserTest extends BaseMapTest
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ static class POJO {
}

static class A2297 {
private String knownField;
String knownField;

@JsonCreator
private A2297(@JsonProperty("knownField") String knownField) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,6 @@

import com.fasterxml.jackson.core.*;

import com.fasterxml.jackson.databind.DeserializationContext;
import com.fasterxml.jackson.databind.JsonDeserializer;
import com.fasterxml.jackson.databind.JsonSerializer;
import com.fasterxml.jackson.databind.KeyDeserializer;
import com.fasterxml.jackson.databind.SerializerProvider;
import com.fasterxml.jackson.databind.annotation.*;
import com.fasterxml.jackson.databind.cfg.HandlerInstantiator;
import com.fasterxml.jackson.databind.cfg.MapperConfig;
Expand Down
Loading

0 comments on commit a64e1bf

Please sign in to comment.