Skip to content

Commit

Permalink
First part of #3044 (JsonDeserializer->ValueDeserializer)
Browse files Browse the repository at this point in the history
  • Loading branch information
cowtowncoder committed Feb 8, 2021
1 parent 3db9730 commit 4d22e36
Show file tree
Hide file tree
Showing 115 changed files with 748 additions and 760 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -921,8 +921,8 @@ public Enum<?> findDefaultEnumValue(MapperConfig<?> config,
/**
* Method for getting a deserializer definition on specified method
* or field.
* Type of definition is either instance (of type {@link JsonDeserializer})
* or Class (of type {@code Class&<JsonDeserializer>});
* Type of definition is either instance (of type {@link ValueDeserializer})
* or Class (of type {@code Class&<ValueDeserializer>});
* type is returned, a runtime exception may be thrown by caller.
*/
public Object findDeserializer(MapperConfig<?> config, Annotated am) {
Expand All @@ -932,8 +932,8 @@ public Object findDeserializer(MapperConfig<?> config, Annotated am) {
/**
* Method for getting a deserializer definition for keys of
* associated <code>Map</code> property.
* Type of definition is either instance (of type {@link JsonDeserializer})
* or Class (of type {@code Class<JsonDeserializer>});
* Type of definition is either instance (of type {@link ValueDeserializer})
* or Class (of type {@code Class<ValueDeserializer>});
* if value of different
* type is returned, a runtime exception may be thrown by caller.
*/
Expand All @@ -945,8 +945,8 @@ public Object findKeyDeserializer(MapperConfig<?> config, Annotated am) {
* Method for getting a deserializer definition for content (values) of
* associated <code>Collection</code>, <code>array</code> or
* <code>Map</code> property.
* Type of definition is either instance (of type {@link JsonDeserializer})
* or Class (of type {@code Class<JsonDeserializer>});
* Type of definition is either instance (of type {@link ValueDeserializer})
* or Class (of type {@code Class<ValueDeserializer>});
* if value of different
* type is returned, a runtime exception may be thrown by caller.
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
* and deserializers, but rather only passed when context
* is known and
* {@link JsonSerializer#createContextual} and
* {@link JsonDeserializer#createContextual} are called.
* {@link ValueDeserializer#createContextual} are called.
* References may (need to) be retained by serializers and deserializers,
* especially when further resolving dependent handlers like value
* serializers/deserializers or structured types.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@
* objects (scrap arrays, containers).
* Constructed by {@link ObjectMapper} (and {@link ObjectReader} based on
* configuration,
* used mostly by {@link JsonDeserializer}s to access contextual information.
* used mostly by {@link ValueDeserializer}s to access contextual information.
*/
public abstract class DeserializationContext
extends DatabindContext
Expand All @@ -71,7 +71,7 @@ public abstract class DeserializationContext
final protected DeserializerFactory _factory;

/**
* Object that handle details of {@link JsonDeserializer} caching.
* Object that handle details of {@link ValueDeserializer} caching.
*/
final protected DeserializerCache _cache;

Expand Down Expand Up @@ -143,7 +143,7 @@ public abstract class DeserializationContext
protected transient ContextAttributes _attributes;

/**
* Type of {@link JsonDeserializer} on which {@link JsonDeserializer#createContextual}
* Type of {@link ValueDeserializer} on which {@link ValueDeserializer#createContextual}
* is being called currently.
*/
protected LinkedNode<JavaType> _currentType;
Expand Down Expand Up @@ -268,13 +268,13 @@ public DeserializationContext setAttribute(Object key, Object value)

/**
* Accessor to {@link JavaType} of currently contextualized
* {@link JsonDeserializer}, if any.
* This is sometimes useful for generic {@link JsonDeserializer}s that
* {@link ValueDeserializer}, if any.
* This is sometimes useful for generic {@link ValueDeserializer}s that
* do not get passed (or do not retain) type information when being
* constructed: happens for example for deserializers constructed
* from annotations.
*
* @return Type of {@link JsonDeserializer} being contextualized,
* @return Type of {@link ValueDeserializer} being contextualized,
* if process is on-going; null if not.
*/
public JavaType getContextualType() {
Expand Down Expand Up @@ -344,7 +344,7 @@ public JsonNode readTree(JsonParser p) throws JacksonException
if (t == JsonToken.VALUE_NULL) {
return getNodeFactory().nullNode();
}
JsonDeserializer<Object> deser = findRootValueDeserializer(ObjectReader.JSON_NODE_TYPE);
ValueDeserializer<Object> deser = findRootValueDeserializer(ObjectReader.JSON_NODE_TYPE);
return (JsonNode) deser.deserialize(p, this);
}

Expand Down Expand Up @@ -378,10 +378,10 @@ public <T> T readValue(JsonParser p, ResolvedType type) throws JacksonException

@SuppressWarnings("unchecked")
public <T> T readValue(JsonParser p, JavaType type) throws JacksonException {
JsonDeserializer<Object> deser = findRootValueDeserializer(type);
ValueDeserializer<Object> deser = findRootValueDeserializer(type);
if (deser == null) {
reportBadDefinition(type,
"Could not find JsonDeserializer for type "+type);
"Could not find `ValueDeserializer` for type "+ClassUtil.getTypeDescription(type));
}
return (T) deser.deserialize(p, this);
}
Expand Down Expand Up @@ -602,12 +602,12 @@ public CoercionAction findCoercionFromBlankString(LogicalType targetType,
* version if necessary, for value reached via specified property.
*/
@SuppressWarnings("unchecked")
public final JsonDeserializer<Object> findContextualValueDeserializer(JavaType type,
public final ValueDeserializer<Object> findContextualValueDeserializer(JavaType type,
BeanProperty prop)
{
JsonDeserializer<Object> deser = _cache.findValueDeserializer(this, _factory, type);
ValueDeserializer<Object> deser = _cache.findValueDeserializer(this, _factory, type);
if (deser != null) {
deser = (JsonDeserializer<Object>) handleSecondaryContextualization(deser, prop, type);
deser = (ValueDeserializer<Object>) handleSecondaryContextualization(deser, prop, type);
}
return deser;
}
Expand All @@ -617,13 +617,13 @@ public final JsonDeserializer<Object> findContextualValueDeserializer(JavaType t
* performing any contextualization (unlike {@link #findContextualValueDeserializer})
* or checking for need to create a {@link TypeDeserializer} (unlike
* {@link #findRootValueDeserializer(JavaType)}.
* This method is usually called from within {@link JsonDeserializer#resolve},
* This method is usually called from within {@link ValueDeserializer#resolve},
* and expectation is that caller then calls either
* {@link #handlePrimaryContextualization(JsonDeserializer, BeanProperty, JavaType)} or
* {@link #handleSecondaryContextualization(JsonDeserializer, BeanProperty, JavaType)} at a
* {@link #handlePrimaryContextualization(ValueDeserializer, BeanProperty, JavaType)} or
* {@link #handleSecondaryContextualization(ValueDeserializer, BeanProperty, JavaType)} at a
* later point, as necessary.
*/
public final JsonDeserializer<Object> findNonContextualValueDeserializer(JavaType type)
public final ValueDeserializer<Object> findNonContextualValueDeserializer(JavaType type)
{
return _cache.findValueDeserializer(this, _factory, type);
}
Expand All @@ -632,14 +632,14 @@ public final JsonDeserializer<Object> findNonContextualValueDeserializer(JavaTyp
* Method for finding a deserializer for root-level value.
*/
@SuppressWarnings("unchecked")
public final JsonDeserializer<Object> findRootValueDeserializer(JavaType type)
public final ValueDeserializer<Object> findRootValueDeserializer(JavaType type)
{
JsonDeserializer<Object> deser = _cache.findValueDeserializer(this,
ValueDeserializer<Object> deser = _cache.findValueDeserializer(this,
_factory, type);
if (deser == null) { // can this occur?
return null;
}
deser = (JsonDeserializer<Object>) handleSecondaryContextualization(deser, null, type);
deser = (ValueDeserializer<Object>) handleSecondaryContextualization(deser, null, type);
TypeDeserializer typeDeser = findTypeDeserializer(type);
if (typeDeser != null) {
// important: contextualize to indicate this is for root value
Expand Down Expand Up @@ -847,7 +847,7 @@ public final ArrayBuilders getArrayBuilders()
/**********************************************************************
*/

public abstract JsonDeserializer<Object> deserializerInstance(Annotated annotated,
public abstract ValueDeserializer<Object> deserializerInstance(Annotated annotated,
Object deserDef);

public abstract KeyDeserializer keyDeserializerInstance(Annotated annotated,
Expand All @@ -864,11 +864,11 @@ public abstract KeyDeserializer keyDeserializerInstance(Annotated annotated,
* Method called for primary property deserializers (ones
* directly created to deserialize values of a POJO property),
* to handle details of calling
* {@link JsonDeserializer#createContextual} with given property context.
* {@link ValueDeserializer#createContextual} with given property context.
*
* @param prop Property for which the given primary deserializer is used; never null.
*/
public JsonDeserializer<?> handlePrimaryContextualization(JsonDeserializer<?> deser,
public ValueDeserializer<?> handlePrimaryContextualization(ValueDeserializer<?> deser,
BeanProperty prop, JavaType type)
{
if (deser != null) {
Expand All @@ -888,15 +888,15 @@ public JsonDeserializer<?> handlePrimaryContextualization(JsonDeserializer<?> de
* but instead created as a component -- such as value deserializers
* for structured types, or deserializers for root values)
* to handle details of resolving
* {@link JsonDeserializer#createContextual} with given property context.
* {@link ValueDeserializer#createContextual} with given property context.
* Given that these deserializers are not directly related to given property
* (or, in case of root value property, to any property), annotations
* accessible may or may not be relevant.
*
* @param prop Property for which deserializer is used, if any; null
* when deserializing root values
*/
public JsonDeserializer<?> handleSecondaryContextualization(JsonDeserializer<?> deser,
public ValueDeserializer<?> handleSecondaryContextualization(ValueDeserializer<?> deser,
BeanProperty prop, JavaType type)
{
if (deser != null) {
Expand Down Expand Up @@ -974,7 +974,7 @@ public Calendar constructCalendar(Date d) {
* @throws JacksonException If there are problems either reading content (underlying parser
* problem) or finding expected scalar value
*/
public String extractScalarFromObject(JsonParser p, JsonDeserializer<?> deser,
public String extractScalarFromObject(JsonParser p, ValueDeserializer<?> deser,
Class<?> scalarType)
throws JacksonException
{
Expand Down Expand Up @@ -1012,10 +1012,10 @@ public <T> T readPropertyValue(JsonParser p, BeanProperty prop, Class<T> type)
public <T> T readPropertyValue(JsonParser p, BeanProperty prop, JavaType type)
throws JacksonException
{
JsonDeserializer<Object> deser = findContextualValueDeserializer(type, prop);
ValueDeserializer<Object> deser = findContextualValueDeserializer(type, prop);
if (deser == null) {
return reportBadDefinition(type, String.format(
"Could not find JsonDeserializer for type %s (via property %s)",
"Could not find `ValueDeserializer` for type %s (via property %s)",
ClassUtil.getTypeDescription(type), ClassUtil.nameOf(prop)));
}
return (T) deser.deserialize(p, this);
Expand Down Expand Up @@ -1097,7 +1097,7 @@ private TreeTraversingParser _treeAsTokens(JsonNode n)
* @return True if there was a configured problem handler that was able to handle the
* problem
*/
public boolean handleUnknownProperty(JsonParser p, JsonDeserializer<?> deser,
public boolean handleUnknownProperty(JsonParser p, ValueDeserializer<?> deser,
Object instanceOrClass, String propName)
throws JacksonException
{
Expand Down Expand Up @@ -1552,7 +1552,7 @@ public JavaType handleMissingTypeId(JavaType baseType,
* this method will simply return null; otherwise {@link InvalidDefinitionException}
* will be thrown.
*/
public void handleBadMerge(JsonDeserializer<?> deser) throws DatabindException
public void handleBadMerge(ValueDeserializer<?> deser) throws DatabindException
{
if (!isEnabled(MapperFeature.IGNORE_MERGE_FOR_UNMERGEABLE)) {
JavaType type = constructType(deser.handledType());
Expand Down Expand Up @@ -1587,7 +1587,7 @@ protected boolean _isCompatible(Class<?> target, Object value)
* recovery is attempted (via {@link DeserializationProblemHandler}, as
* problem is considered to be difficult to recover from, in general.
*/
public void reportWrongTokenException(JsonDeserializer<?> deser,
public void reportWrongTokenException(ValueDeserializer<?> deser,
JsonToken expToken, String msg, Object... msgArgs)
throws DatabindException
{
Expand Down Expand Up @@ -1639,7 +1639,7 @@ public <T> T reportUnresolvedObjectId(ObjectIdReader oidReader, Object bean)
* Helper method used to indicate a problem with input in cases where more
* specific <code>reportXxx()</code> method was not available.
*/
public <T> T reportInputMismatch(JsonDeserializer<?> src,
public <T> T reportInputMismatch(ValueDeserializer<?> src,
String msg, Object... msgArgs)
throws DatabindException
{
Expand Down Expand Up @@ -1723,7 +1723,7 @@ public <T> T reportPropertyInputMismatch(JavaType targetType, String propertyNam
* Helper method used to indicate a problem with input in cases where specific
* input coercion was not allowed.
*/
public <T> T reportBadCoercion(JsonDeserializer<?> src,
public <T> T reportBadCoercion(ValueDeserializer<?> src,
Class<?> targetType, Object inputValue,
String msg, Object... msgArgs)
throws DatabindException
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -438,7 +438,7 @@ public enum DeserializationFeature implements ConfigFeature

/**
* Feature that determines whether {@link ObjectReader} should
* try to eagerly fetch necessary {@link JsonDeserializer} when
* try to eagerly fetch necessary {@link ValueDeserializer} when
* possible. This improves performance in cases where similarly
* configured {@link ObjectReader} instance is used multiple
* times; and should not significantly affect single-use cases.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ public class MappingIterator<T> implements Iterator<T>, Closeable
/**
* Deserializer for individual element values.
*/
protected final JsonDeserializer<T> _deserializer;
protected final ValueDeserializer<T> _deserializer;

/**
* Underlying parser used for reading content to bind. Initialized
Expand Down Expand Up @@ -119,13 +119,13 @@ public class MappingIterator<T> implements Iterator<T>, Closeable
*/
@SuppressWarnings("unchecked")
protected MappingIterator(JavaType type, JsonParser p, DeserializationContext ctxt,
JsonDeserializer<?> deser,
ValueDeserializer<?> deser,
boolean managedParser, Object valueToUpdate)
{
_type = type;
_parser = p;
_context = ctxt;
_deserializer = (JsonDeserializer<T>) deser;
_deserializer = (ValueDeserializer<T>) deser;
_closeParser = managedParser;
if (valueToUpdate == null) {
_updatedValue = null;
Expand Down
16 changes: 8 additions & 8 deletions src/main/java/com/fasterxml/jackson/databind/ObjectMapper.java
Original file line number Diff line number Diff line change
Expand Up @@ -246,8 +246,8 @@ protected Object readResolve() {
* no type information is needed for base type), or type-wrapped
* deserializers (if it is needed)
*/
protected final ConcurrentHashMap<JavaType, JsonDeserializer<Object>> _rootDeserializers
= new ConcurrentHashMap<JavaType, JsonDeserializer<Object>>(64, 0.6f, 2);
protected final ConcurrentHashMap<JavaType, ValueDeserializer<Object>> _rootDeserializers
= new ConcurrentHashMap<JavaType, ValueDeserializer<Object>>(64, 0.6f, 2);

/*
/**********************************************************************
Expand Down Expand Up @@ -1031,7 +1031,7 @@ public <T> MappingIterator<T> readValues(JsonParser p, JavaType valueType)
{
_assertNotNull("p", p);
DeserializationContext ctxt = _deserializationContext(p);
JsonDeserializer<?> deser = _findRootDeserializer(ctxt, valueType);
ValueDeserializer<?> deser = _findRootDeserializer(ctxt, valueType);
// false -> do NOT close JsonParser (since caller passed it)
return new MappingIterator<T>(valueType, p, ctxt, deser,
false, null);
Expand Down Expand Up @@ -2216,7 +2216,7 @@ protected Object _convert(Object fromValue, JavaType toValueType)
} else if (t == JsonToken.END_ARRAY || t == JsonToken.END_OBJECT) {
result = null;
} else { // pointing to event other than null
JsonDeserializer<Object> deser = _findRootDeserializer(readCtxt, toValueType);
ValueDeserializer<Object> deser = _findRootDeserializer(readCtxt, toValueType);
// note: no handling of unwrapping
result = deser.deserialize(p, readCtxt);
}
Expand Down Expand Up @@ -2368,7 +2368,7 @@ protected Object _readValue(DeserializationContextExt ctxt, JsonParser p,
JsonToken t = _initForReading(p, valueType);

if (t == JsonToken.VALUE_NULL) {
// Ask JsonDeserializer what 'null value' to use:
// Ask deserializer what 'null value' to use:
result = _findRootDeserializer(ctxt, valueType).getNullValue(ctxt);
} else if (t == JsonToken.END_ARRAY || t == JsonToken.END_OBJECT) {
result = null;
Expand All @@ -2392,7 +2392,7 @@ protected Object _readMapAndClose(DeserializationContextExt ctxt,
Object result;
JsonToken t = _initForReading(p, valueType);
if (t == JsonToken.VALUE_NULL) {
// Ask JsonDeserializer what 'null value' to use:
// Ask deserializer what 'null value' to use:
result = _findRootDeserializer(ctxt, valueType).getNullValue(ctxt);
} else if (t == JsonToken.END_ARRAY || t == JsonToken.END_OBJECT) {
result = null;
Expand Down Expand Up @@ -2570,12 +2570,12 @@ protected ObjectWriter _newWriter(SerializationConfig config,
/**
* Method called to locate deserializer for the passed root-level value.
*/
protected JsonDeserializer<Object> _findRootDeserializer(DeserializationContext ctxt,
protected ValueDeserializer<Object> _findRootDeserializer(DeserializationContext ctxt,
JavaType valueType)
throws JacksonException
{
// First: have we already seen it?
JsonDeserializer<Object> deser = _rootDeserializers.get(valueType);
ValueDeserializer<Object> deser = _rootDeserializers.get(valueType);
if (deser != null) {
return deser;
}
Expand Down
Loading

0 comments on commit 4d22e36

Please sign in to comment.