Skip to content

Commit

Permalink
Undo earlier refactoring: can't get rid of DeserializationContext, le…
Browse files Browse the repository at this point in the history
…ave as-is
  • Loading branch information
cowtowncoder committed May 15, 2024
1 parent b9d1e90 commit c6f24a1
Showing 1 changed file with 14 additions and 30 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -560,7 +560,7 @@ protected void _addImplicitConstructorCreators(DeserializationContext ctxt,
}
NameTransformer unwrapper = intr.findUnwrappingNameTransformer(param);
if (unwrapper != null) {
_reportUnwrappedCreatorProperty(beanDesc, param);
_reportUnwrappedCreatorProperty(ctxt, beanDesc, param);
/*
properties[i] = constructCreatorProperty(ctxt, beanDesc, UNWRAPPED_CREATOR_PARAM_NAME, i, param, null);
++explicitNameCount;
Expand Down Expand Up @@ -606,7 +606,7 @@ protected void _addImplicitConstructorCreators(DeserializationContext ctxt,
+ctor.getDeclaringClass().getName()+" cannot use @JsonCreator for constructors");
}
*/
_reportBadTypeDefinition(beanDesc,
ctxt.reportBadTypeDefinition(beanDesc,
"Argument #%d of constructor %s has no property name annotation; must have name when multiple-parameter constructor annotated as Creator",
nonAnnotatedParamIndex, ctor);
}
Expand Down Expand Up @@ -742,7 +742,7 @@ protected void _addImplicitFactoryCreators(DeserializationContext ctxt,
}
NameTransformer unwrapper = intr.findUnwrappingNameTransformer(param);
if (unwrapper != null) {
_reportUnwrappedCreatorProperty(beanDesc, param);
_reportUnwrappedCreatorProperty(ctxt, beanDesc, param);
/*
properties[i] = constructCreatorProperty(ctxt, beanDesc, UNWRAPPED_CREATOR_PARAM_NAME, i, param, null);
++implicitNameCount;
Expand Down Expand Up @@ -786,7 +786,7 @@ protected void _addImplicitFactoryCreators(DeserializationContext ctxt,
// secondary: all but one injectable, one un-annotated (un-named)
creators.addDelegatingCreator(factory, false, properties, 0);
} else { // otherwise, epic fail
_reportBadTypeDefinition(beanDesc,
ctxt.reportBadTypeDefinition(beanDesc,
"Argument #%d of factory method %s has no property name annotation; must have name when multiple-parameter constructor annotated as Creator",
(nonAnnotatedParam == null) ? -1 : nonAnnotatedParam.getIndex(),
factory);
Expand Down Expand Up @@ -829,13 +829,13 @@ protected void _addExplicitDelegatingCreator(DeserializationContext ctxt,
continue;
}
// Illegal to have more than one value to delegate to
_reportBadTypeDefinition(beanDesc,
ctxt.reportBadTypeDefinition(beanDesc,
"More than one argument (#%d and #%d) left as delegating for Creator %s: only one allowed",
ix, i, candidate);
}
// Also, let's require that one Delegating argument does eixt
if (ix < 0) {
_reportBadTypeDefinition(beanDesc,
ctxt.reportBadTypeDefinition(beanDesc,
"No argument left as delegating for Creator %s: exactly one required", candidate);
}
// 17-Jan-2018, tatu: as per [databind#1853] need to ensure we will distinguish
Expand Down Expand Up @@ -876,14 +876,14 @@ protected void _addExplicitPropertyCreator(DeserializationContext ctxt,
// as that will not work with Creators well at all
NameTransformer unwrapper = ctxt.getAnnotationIntrospector().findUnwrappingNameTransformer(param);
if (unwrapper != null) {
_reportUnwrappedCreatorProperty(beanDesc, param);
_reportUnwrappedCreatorProperty(ctxt, beanDesc, param);
/*
properties[i] = constructCreatorProperty(ctxt, beanDesc, UNWRAPPED_CREATOR_PARAM_NAME, i, param, null);
++explicitNameCount;
*/
}
name = candidate.findImplicitParamName(i);
_validateNamedPropertyParameter(beanDesc, candidate, i,
_validateNamedPropertyParameter(ctxt, beanDesc, candidate, i,
name, injectId);
}
properties[i] = constructCreatorProperty(ctxt, beanDesc, name, i, param, injectId);
Expand Down Expand Up @@ -941,13 +941,13 @@ protected void _addExplicitAnyCreator(DeserializationContext ctxt,
paramName = candidate.paramName(0);
// [databind#2977]: Need better exception if name missing
if (paramName == null) {
_validateNamedPropertyParameter(beanDesc, candidate, 0,
_validateNamedPropertyParameter(ctxt, beanDesc, candidate, 0,
paramName, injectId);
}
break;

case REQUIRE_MODE:
_reportBadTypeDefinition(beanDesc,
ctxt.reportBadTypeDefinition(beanDesc,
"Single-argument constructor (%s) is annotated but no 'mode' defined; `ConstructorDetector`"
+ "configured with `SingleArgConstructor.REQUIRE_MODE`",
candidate.creator());
Expand Down Expand Up @@ -1148,27 +1148,27 @@ protected boolean _handleSingleArgumentCreator(CreatorCollector creators,
// has name or is marked as Injectable
//
// @since 2.12.1
protected void _validateNamedPropertyParameter(
protected void _validateNamedPropertyParameter(DeserializationContext ctxt,
BeanDescription beanDesc,
CreatorCandidate candidate, int paramIndex,
PropertyName name, JacksonInject.Value injectId)
throws JsonMappingException
{
// Must be injectable or have name; without either won't work
if ((name == null) && (injectId == null)) {
_reportBadTypeDefinition(beanDesc,
ctxt.reportBadTypeDefinition(beanDesc,
"Argument #%d of constructor %s has no property name (and is not Injectable): can not use as property-based Creator",
paramIndex, candidate);
}
}

// 01-Dec-2016, tatu: As per [databind#265] we cannot yet support passing
// of unwrapped values through creator properties, so fail fast
protected void _reportUnwrappedCreatorProperty(
protected void _reportUnwrappedCreatorProperty(DeserializationContext ctxt,
BeanDescription beanDesc, AnnotatedParameter param)
throws JsonMappingException
{
_reportBadTypeDefinition(beanDesc,
ctxt.reportBadTypeDefinition(beanDesc,
"Cannot define Creator parameter %d as `@JsonUnwrapped`: combination not yet supported",
param.getIndex());
}
Expand Down Expand Up @@ -1312,22 +1312,6 @@ protected PropertyMetadata _getSetterInfo(MapperConfig<?> config,
return metadata;
}

// Inlined version of:
// return ctxt.reportBadTypeDefinition(bean, msg, msgArgs);
// @since 2.18
private <T> T _reportBadTypeDefinition(BeanDescription bean,
String msg, Object... msgArgs)
throws JsonMappingException
{

String beanDesc = ClassUtil.nameOf(bean.getBeanClass());
if (msgArgs.length > 0) {
msg = String.format(msg, msgArgs);
}
msg = String.format("Invalid type definition for type %s: %s", beanDesc, msg);
throw InvalidDefinitionException.from((JsonParser) null, msg, bean, null);
}

/*
/**********************************************************************
/* DeserializerFactory impl: array deserializers
Expand Down

0 comments on commit c6f24a1

Please sign in to comment.