Skip to content

Commit

Permalink
more twiddling of parameter ordering
Browse files Browse the repository at this point in the history
  • Loading branch information
cowtowncoder committed Apr 18, 2018
1 parent 9725b3d commit 27f30ab
Show file tree
Hide file tree
Showing 8 changed files with 54 additions and 64 deletions.
Expand Up @@ -639,8 +639,8 @@ public <T extends BeanDescription> T introspectForBuilder(JavaType type) {
public TypeDeserializer findTypeDeserializer(JavaType baseType) public TypeDeserializer findTypeDeserializer(JavaType baseType)
throws JsonMappingException throws JsonMappingException
{ {
BeanDescription bean = introspectClassAnnotations(baseType.getRawClass()); BeanDescription beanDesc = introspectClassAnnotations(baseType.getRawClass());
return getTypeResolverProvider().findTypeDeserializer(this, return getTypeResolverProvider().findTypeDeserializer(this, baseType,
bean.getClassInfo(), baseType); beanDesc.getClassInfo());
} }
} }
Expand Up @@ -835,7 +835,7 @@ protected JsonSerializer<Object> _createAndCacheUntypedSerializer(Class<?> rawTy
JsonFormat.Value format = beanDesc.findExpectedFormat(); JsonFormat.Value format = beanDesc.findExpectedFormat();
JsonSerializer<Object> ser; JsonSerializer<Object> ser;
try { try {
ser = _serializerFactory.createSerializer(this, beanDesc, fullType, format); ser = _serializerFactory.createSerializer(this, fullType, beanDesc, format);
} catch (IllegalArgumentException iae) { } catch (IllegalArgumentException iae) {
// We better only expose checked exceptions, since those are what caller is expected to handle // We better only expose checked exceptions, since those are what caller is expected to handle
throw _mappingProblem(iae, iae.getMessage()); throw _mappingProblem(iae, iae.getMessage());
Expand All @@ -853,7 +853,7 @@ protected JsonSerializer<Object> _createAndCacheUntypedSerializer(JavaType type)
JsonFormat.Value format = beanDesc.findExpectedFormat(); JsonFormat.Value format = beanDesc.findExpectedFormat();
JsonSerializer<Object> ser; JsonSerializer<Object> ser;
try { try {
ser = _serializerFactory.createSerializer(this, beanDesc, type, format); ser = _serializerFactory.createSerializer(this, type, beanDesc, format);
} catch (IllegalArgumentException iae) { } catch (IllegalArgumentException iae) {
// We better only expose checked exceptions, since those are what caller is expected to handle // We better only expose checked exceptions, since those are what caller is expected to handle
throw _mappingProblem(iae, iae.getMessage()); throw _mappingProblem(iae, iae.getMessage());
Expand Down
Expand Up @@ -1553,8 +1553,8 @@ public TypeDeserializer findTypeDeserializer(final DeserializationConfig config,
throws JsonMappingException throws JsonMappingException
{ {
BeanDescription bean = config.introspectClassAnnotations(baseType.getRawClass()); BeanDescription bean = config.introspectClassAnnotations(baseType.getRawClass());
return config.getTypeResolverProvider().findTypeDeserializer(config, return config.getTypeResolverProvider().findTypeDeserializer(config, baseType,
bean.getClassInfo(), baseType); bean.getClassInfo());


// JavaType defaultType = mapAbstractType(config, baseType); // JavaType defaultType = mapAbstractType(config, baseType);


Expand Down
Expand Up @@ -50,7 +50,7 @@ public class TypeResolverProvider
* @return Type resolver builder for given type, if one found; null if none * @return Type resolver builder for given type, if one found; null if none
*/ */
public TypeSerializer findTypeSerializer(SerializationConfig config, public TypeSerializer findTypeSerializer(SerializationConfig config,
AnnotatedClass classInfo, JavaType baseType) JavaType baseType, AnnotatedClass classInfo)
throws JsonMappingException throws JsonMappingException
{ {
TypeResolverBuilder<?> b = _findTypeResolver(config, classInfo, baseType); TypeResolverBuilder<?> b = _findTypeResolver(config, classInfo, baseType);
Expand All @@ -71,7 +71,7 @@ public TypeSerializer findTypeSerializer(SerializationConfig config,
} }


public TypeDeserializer findTypeDeserializer(DeserializationConfig config, public TypeDeserializer findTypeDeserializer(DeserializationConfig config,
AnnotatedClass classInfo, JavaType baseType) JavaType baseType, AnnotatedClass classInfo)
throws JsonMappingException throws JsonMappingException
{ {
TypeResolverBuilder<?> b = _findTypeResolver(config, classInfo, baseType); TypeResolverBuilder<?> b = _findTypeResolver(config, classInfo, baseType);
Expand Down Expand Up @@ -116,7 +116,7 @@ public TypeSerializer findPropertyTypeSerializer(SerializationConfig config,
// No annotation on property? Then base it on actual type (and further, default typing if need be) // No annotation on property? Then base it on actual type (and further, default typing if need be)
if (b == null) { if (b == null) {
BeanDescription bean = config.introspectClassAnnotations(baseType.getRawClass()); BeanDescription bean = config.introspectClassAnnotations(baseType.getRawClass());
return findTypeSerializer(config, bean.getClassInfo(), baseType); return findTypeSerializer(config, baseType, bean.getClassInfo());
} }
Collection<NamedType> subtypes = config.getSubtypeResolver().collectAndResolveSubtypesByClass( Collection<NamedType> subtypes = config.getSubtypeResolver().collectAndResolveSubtypesByClass(
config, accessor, baseType); config, accessor, baseType);
Expand All @@ -136,9 +136,8 @@ public TypeDeserializer findPropertyTypeDeserializer(DeserializationConfig confi
} }
// No annotation on property? Then base it on actual type (and further, default typing if need be) // No annotation on property? Then base it on actual type (and further, default typing if need be)
if (b == null) { if (b == null) {
return findTypeDeserializer(config, return findTypeDeserializer(config, baseType,
config.introspectClassAnnotations(baseType.getRawClass()).getClassInfo(), config.introspectClassAnnotations(baseType.getRawClass()).getClassInfo());
baseType);
} }
Collection<NamedType> subtypes = config.getSubtypeResolver().collectAndResolveSubtypesByTypeId(config, Collection<NamedType> subtypes = config.getSubtypeResolver().collectAndResolveSubtypesByTypeId(config,
accessor, baseType); accessor, baseType);
Expand Down Expand Up @@ -166,8 +165,8 @@ public TypeSerializer findPropertyContentTypeSerializer(SerializationConfig conf
TypeResolverBuilder<?> b = _findTypeResolver(config, accessor, containerType); TypeResolverBuilder<?> b = _findTypeResolver(config, accessor, containerType);
// No annotation on property? Then base it on actual type (and further, default typing if need be) // No annotation on property? Then base it on actual type (and further, default typing if need be)
if (b == null) { if (b == null) {
BeanDescription bean = config.introspectClassAnnotations(contentType.getRawClass()); BeanDescription beanDesc = config.introspectClassAnnotations(contentType.getRawClass());
return findTypeSerializer(config, bean.getClassInfo(), contentType); return findTypeSerializer(config, contentType, beanDesc.getClassInfo());
} }
Collection<NamedType> subtypes = config.getSubtypeResolver().collectAndResolveSubtypesByClass( Collection<NamedType> subtypes = config.getSubtypeResolver().collectAndResolveSubtypesByClass(
config, accessor, contentType); config, accessor, contentType);
Expand All @@ -186,9 +185,8 @@ public TypeDeserializer findPropertyContentTypeDeserializer(DeserializationConfi
} }
TypeResolverBuilder<?> b = _findTypeResolver(config, accessor, containerType); TypeResolverBuilder<?> b = _findTypeResolver(config, accessor, containerType);
if (b == null) { if (b == null) {
return findTypeDeserializer(config, return findTypeDeserializer(config, contentType,
config.introspectClassAnnotations(contentType.getRawClass()).getClassInfo(), config.introspectClassAnnotations(contentType.getRawClass()).getClassInfo());
contentType);
} }
Collection<NamedType> subtypes = config.getSubtypeResolver().collectAndResolveSubtypesByTypeId(config, Collection<NamedType> subtypes = config.getSubtypeResolver().collectAndResolveSubtypesByTypeId(config,
accessor, contentType); accessor, contentType);
Expand Down
Expand Up @@ -239,10 +239,10 @@ public JsonSerializer<Object> createKeySerializer(SerializationConfig config,
*/ */
@Override @Override
public TypeSerializer findTypeSerializer(SerializationConfig config, public TypeSerializer findTypeSerializer(SerializationConfig config,
BeanDescription beanDesc, JavaType baseType) throws JsonMappingException JavaType baseType, BeanDescription beanDesc) throws JsonMappingException
{ {
return config.getTypeResolverProvider().findTypeSerializer(config, return config.getTypeResolverProvider().findTypeSerializer(config,
beanDesc.getClassInfo(), baseType); baseType, beanDesc.getClassInfo());
} }


@Override @Override
Expand Down
Expand Up @@ -116,8 +116,8 @@ public SerializerFactory withConfig(SerializerFactoryConfig config)
*/ */
@Override @Override
@SuppressWarnings("unchecked") @SuppressWarnings("unchecked")
public JsonSerializer<Object> createSerializer(SerializerProvider ctxt, public JsonSerializer<Object> createSerializer(SerializerProvider ctxt, JavaType origType,
BeanDescription beanDesc, JavaType origType, JsonFormat.Value format) BeanDescription beanDesc, JsonFormat.Value format)
throws JsonMappingException throws JsonMappingException
{ {
// Very first thing, let's check if there is explicit serializer annotation: // Very first thing, let's check if there is explicit serializer annotation:
Expand Down
Expand Up @@ -27,7 +27,7 @@ public abstract class SerializerFactory
* @since 3.0 (last argument added) * @since 3.0 (last argument added)
*/ */
public abstract JsonSerializer<Object> createSerializer(SerializerProvider prov, public abstract JsonSerializer<Object> createSerializer(SerializerProvider prov,
BeanDescription beanDesc, JavaType baseType, JsonFormat.Value format) JavaType baseType, BeanDescription beanDesc, JsonFormat.Value format)
throws JsonMappingException; throws JsonMappingException;


/** /**
Expand All @@ -40,15 +40,14 @@ public abstract JsonSerializer<Object> createSerializer(SerializerProvider prov,
* @return Type serializer to use for the base type, if one is needed; null if not. * @return Type serializer to use for the base type, if one is needed; null if not.
*/ */
public abstract TypeSerializer findTypeSerializer(SerializationConfig config, public abstract TypeSerializer findTypeSerializer(SerializationConfig config,
BeanDescription beanDesc, JavaType baseType) JavaType baseType, BeanDescription beanDesc)
throws JsonMappingException; throws JsonMappingException;


public TypeSerializer findTypeSerializer(SerializationConfig config, public TypeSerializer findTypeSerializer(SerializationConfig config,
JavaType baseType) throws JsonMappingException JavaType baseType) throws JsonMappingException
{ {
return findTypeSerializer(config, return findTypeSerializer(config, baseType,
config.introspectClassAnnotations(baseType), config.introspectClassAnnotations(baseType));
baseType);
} }


/** /**
Expand Down Expand Up @@ -126,7 +125,7 @@ public JsonSerializer<Object> createSerializer(SerializerProvider prov, JavaType
throws JsonMappingException throws JsonMappingException
{ {
BeanDescription beanDesc = prov.getConfig().introspect(baseType); BeanDescription beanDesc = prov.getConfig().introspect(baseType);
return createSerializer(prov, beanDesc, baseType, return createSerializer(prov, baseType, beanDesc,
beanDesc.findExpectedFormat()); beanDesc.findExpectedFormat());
} }
} }
Expand Up @@ -27,25 +27,21 @@ public class EnumSerializer
private static final long serialVersionUID = 1L; private static final long serialVersionUID = 1L;


/** /**
* This map contains pre-resolved values (since there are ways * This map contains pre-resolved values (since there are ways to customize
* to customize actual String constants to use) to use as * actual String constants to use) to use as serializations.
* serializations.
*/ */
protected final EnumValues _values; protected final EnumValues _values;


/** /**
* Flag that is set if we statically know serialization choice * Flag that is set if we statically know serialization choice between
* between index and textual format (null if it needs to be dynamically * index and textual format (null if it needs to be dynamically checked).
* checked).
*
* @since 2.1
*/ */
protected final Boolean _serializeAsIndex; protected final Boolean _serializeAsIndex;


/* /*
/********************************************************** /**********************************************************************
/* Construction, initialization /* Life-cycle
/********************************************************** /**********************************************************************
*/ */


public EnumSerializer(EnumValues v, Boolean serializeAsIndex) public EnumSerializer(EnumValues v, Boolean serializeAsIndex)
Expand All @@ -58,17 +54,14 @@ public EnumSerializer(EnumValues v, Boolean serializeAsIndex)
/** /**
* Factory method used by {@link com.fasterxml.jackson.databind.ser.BasicSerializerFactory} * Factory method used by {@link com.fasterxml.jackson.databind.ser.BasicSerializerFactory}
* for constructing serializer instance of Enum types. * for constructing serializer instance of Enum types.
*
* @since 2.1
*/ */
@SuppressWarnings("unchecked") @SuppressWarnings("unchecked")
public static EnumSerializer construct(Class<?> enumClass, SerializationConfig config, public static EnumSerializer construct(Class<?> enumClass, SerializationConfig config,
BeanDescription beanDesc, JsonFormat.Value format) BeanDescription beanDesc, JsonFormat.Value format)
{ {
/* 08-Apr-2015, tatu: As per [databind#749], we cannot statically determine // 08-Apr-2015, tatu: As per [databind#749], we cannot statically determine
* between name() and toString(), need to construct `EnumValues` with names, // between name() and toString(), need to construct `EnumValues` with names,
* handle toString() case dynamically (for example) // handle toString() case dynamically (for example)
*/
EnumValues v = EnumValues.constructFromName(config, (Class<Enum<?>>) enumClass); EnumValues v = EnumValues.constructFromName(config, (Class<Enum<?>>) enumClass);
Boolean serializeAsIndex = _isShapeWrittenUsingIndex(enumClass, format, true, null); Boolean serializeAsIndex = _isShapeWrittenUsingIndex(enumClass, format, true, null);
return new EnumSerializer(v, serializeAsIndex); return new EnumSerializer(v, serializeAsIndex);
Expand All @@ -80,10 +73,10 @@ public static EnumSerializer construct(Class<?> enumClass, SerializationConfig c
* choice here, however. * choice here, however.
*/ */
@Override @Override
public JsonSerializer<?> createContextual(SerializerProvider serializers, public JsonSerializer<?> createContextual(SerializerProvider ctxt,
BeanProperty property) throws JsonMappingException BeanProperty property) throws JsonMappingException
{ {
JsonFormat.Value format = findFormatOverrides(serializers, JsonFormat.Value format = findFormatOverrides(ctxt,
property, handledType()); property, handledType());
if (format != null) { if (format != null) {
Class<?> type = handledType(); Class<?> type = handledType();
Expand All @@ -97,40 +90,40 @@ public JsonSerializer<?> createContextual(SerializerProvider serializers,
} }


/* /*
/********************************************************** /**********************************************************************
/* Extended API for Jackson databind core /* Extended API for Jackson databind core
/********************************************************** /**********************************************************************
*/ */


public EnumValues getEnumValues() { return _values; } public EnumValues getEnumValues() { return _values; }


/* /*
/********************************************************** /**********************************************************************
/* Actual serialization /* Actual serialization
/********************************************************** /**********************************************************************
*/ */


@Override @Override
public final void serialize(Enum<?> en, JsonGenerator gen, SerializerProvider serializers) public final void serialize(Enum<?> en, JsonGenerator g, SerializerProvider ctxt)
throws IOException throws IOException
{ {
// [JACKSON-684]: serialize as index? // Serialize as index?
if (_serializeAsIndex(serializers)) { if (_serializeAsIndex(ctxt)) {
gen.writeNumber(en.ordinal()); g.writeNumber(en.ordinal());
return; return;
} }
// [databind#749]: or via toString()? // [databind#749]: or via toString()?
if (serializers.isEnabled(SerializationFeature.WRITE_ENUMS_USING_TO_STRING)) { if (ctxt.isEnabled(SerializationFeature.WRITE_ENUMS_USING_TO_STRING)) {
gen.writeString(en.toString()); g.writeString(en.toString());
return; return;
} }
gen.writeString(_values.serializedValueFor(en)); g.writeString(_values.serializedValueFor(en));
} }


/* /*
/********************************************************** /**********************************************************************
/* Schema support /* Schema support
/********************************************************** /**********************************************************************
*/ */


@Override @Override
Expand Down Expand Up @@ -163,17 +156,17 @@ public void acceptJsonFormatVisitor(JsonFormatVisitorWrapper visitor, JavaType t
} }


/* /*
/********************************************************** /**********************************************************************
/* Helper methods /* Helper methods
/********************************************************** /**********************************************************************
*/ */


protected final boolean _serializeAsIndex(SerializerProvider serializers) protected final boolean _serializeAsIndex(SerializerProvider ctxt)
{ {
if (_serializeAsIndex != null) { if (_serializeAsIndex != null) {
return _serializeAsIndex.booleanValue(); return _serializeAsIndex.booleanValue();
} }
return serializers.isEnabled(SerializationFeature.WRITE_ENUMS_USING_INDEX); return ctxt.isEnabled(SerializationFeature.WRITE_ENUMS_USING_INDEX);
} }


/** /**
Expand Down

0 comments on commit 27f30ab

Please sign in to comment.