Skip to content

Commit

Permalink
More refactoring for #4515
Browse files Browse the repository at this point in the history
  • Loading branch information
cowtowncoder committed May 15, 2024
1 parent 497ac5f commit 3694240
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -414,6 +414,12 @@ public <T> T reportBadDefinition(Class<?> type, String msg) throws JsonMappingEx
return reportBadDefinition(constructType(type), msg);
}

/**
* @since 2.18
*/
public abstract <T> T reportBadTypeDefinition(BeanDescription bean,
String msg, Object... msgArgs) throws JsonMappingException;

/*
/**********************************************************
/* Helper methods
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1857,11 +1857,12 @@ public <T> T reportTrailingTokens(Class<?> targetType,
*
* @since 2.9
*/
@Override // since 2.18
public <T> T reportBadTypeDefinition(BeanDescription bean,
String msg, Object... msgArgs) throws JsonMappingException {
msg = _format(msg, msgArgs);
String msg, Object... msgArgs) throws JsonMappingException
{
String beanDesc = ClassUtil.nameOf(bean.getBeanClass());
msg = String.format("Invalid type definition for type %s: %s", beanDesc, msg);
msg = String.format("Invalid type definition for type %s: %s", beanDesc, _format(msg, msgArgs));
throw InvalidDefinitionException.from(_parser, msg, bean, null);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1291,12 +1291,10 @@ public void reportMappingProblem(String message, Object... args) throws JsonMapp
*
* @since 2.9
*/
@Override // since 2.18
public <T> T reportBadTypeDefinition(BeanDescription bean,
String msg, Object... msgArgs) throws JsonMappingException {
String beanDesc = "N/A";
if (bean != null) {
beanDesc = ClassUtil.nameOf(bean.getBeanClass());
}
String beanDesc = (bean == null) ? "N/A" : ClassUtil.nameOf(bean.getBeanClass());
msg = String.format("Invalid type definition for type %s: %s",
beanDesc, _format(msg, msgArgs));
throw InvalidDefinitionException.from(getGenerator(), msg, bean, null);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -265,8 +265,8 @@ protected ValueInstantiator _constructDefaultValueInstantiator(DeserializationCo
// 15-Mar-2015, tatu: Alas, this won't help with constructors that only have implicit
// names. Those will need to be resolved later on.
final CreatorCollector creators = new CreatorCollector(beanDesc, config);
Map<AnnotatedWithParams,BeanPropertyDefinition[]> creatorDefs = _findCreatorsFromProperties(ctxt,
beanDesc);
Map<AnnotatedWithParams,BeanPropertyDefinition[]> creatorDefs =
_findCreatorsFromProperties(beanDesc);
ccState = new CreatorCollectionState(config, beanDesc, vchecker,
creators, creatorDefs);
}
Expand Down Expand Up @@ -307,7 +307,7 @@ protected ValueInstantiator _constructDefaultValueInstantiator(DeserializationCo
return ccState.creators.constructValueInstantiator(ctxt);
}

protected Map<AnnotatedWithParams,BeanPropertyDefinition[]> _findCreatorsFromProperties(DeserializationContext ctxt,
protected Map<AnnotatedWithParams,BeanPropertyDefinition[]> _findCreatorsFromProperties(
BeanDescription beanDesc) throws JsonMappingException
{
Map<AnnotatedWithParams,BeanPropertyDefinition[]> result = Collections.emptyMap();
Expand All @@ -327,9 +327,15 @@ protected Map<AnnotatedWithParams,BeanPropertyDefinition[]> _findCreatorsFromPro
result.put(owner, defs);
} else {
if (defs[index] != null) {
ctxt.reportBadTypeDefinition(beanDesc,
"Conflict: parameter #%d of %s bound to more than one property; %s vs %s",
index, owner, defs[index], propDef);
// Inlined copy of "DeserializationContext.reportBadTypeDefinition()"
String msg = String.format(
"Conflict: parameter #%d of %s bound to more than one property; %s vs %s",
index, owner, defs[index], propDef);
String errorMsg =
String.format("Invalid type definition for type %s: %s",
ClassUtil.nameOf(beanDesc.getBeanClass()), msg);
throw InvalidDefinitionException.from((JsonParser) null, errorMsg,
beanDesc, null);
}
}
defs[index] = propDef;
Expand Down

0 comments on commit 3694240

Please sign in to comment.