Skip to content

Commit 3694240

Browse files
committed
More refactoring for #4515
1 parent 497ac5f commit 3694240

File tree

4 files changed

+24
-13
lines changed

4 files changed

+24
-13
lines changed

src/main/java/com/fasterxml/jackson/databind/DatabindContext.java

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -414,6 +414,12 @@ public <T> T reportBadDefinition(Class<?> type, String msg) throws JsonMappingEx
414414
return reportBadDefinition(constructType(type), msg);
415415
}
416416

417+
/**
418+
* @since 2.18
419+
*/
420+
public abstract <T> T reportBadTypeDefinition(BeanDescription bean,
421+
String msg, Object... msgArgs) throws JsonMappingException;
422+
417423
/*
418424
/**********************************************************
419425
/* Helper methods

src/main/java/com/fasterxml/jackson/databind/DeserializationContext.java

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1857,11 +1857,12 @@ public <T> T reportTrailingTokens(Class<?> targetType,
18571857
*
18581858
* @since 2.9
18591859
*/
1860+
@Override // since 2.18
18601861
public <T> T reportBadTypeDefinition(BeanDescription bean,
1861-
String msg, Object... msgArgs) throws JsonMappingException {
1862-
msg = _format(msg, msgArgs);
1862+
String msg, Object... msgArgs) throws JsonMappingException
1863+
{
18631864
String beanDesc = ClassUtil.nameOf(bean.getBeanClass());
1864-
msg = String.format("Invalid type definition for type %s: %s", beanDesc, msg);
1865+
msg = String.format("Invalid type definition for type %s: %s", beanDesc, _format(msg, msgArgs));
18651866
throw InvalidDefinitionException.from(_parser, msg, bean, null);
18661867
}
18671868

src/main/java/com/fasterxml/jackson/databind/SerializerProvider.java

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1291,12 +1291,10 @@ public void reportMappingProblem(String message, Object... args) throws JsonMapp
12911291
*
12921292
* @since 2.9
12931293
*/
1294+
@Override // since 2.18
12941295
public <T> T reportBadTypeDefinition(BeanDescription bean,
12951296
String msg, Object... msgArgs) throws JsonMappingException {
1296-
String beanDesc = "N/A";
1297-
if (bean != null) {
1298-
beanDesc = ClassUtil.nameOf(bean.getBeanClass());
1299-
}
1297+
String beanDesc = (bean == null) ? "N/A" : ClassUtil.nameOf(bean.getBeanClass());
13001298
msg = String.format("Invalid type definition for type %s: %s",
13011299
beanDesc, _format(msg, msgArgs));
13021300
throw InvalidDefinitionException.from(getGenerator(), msg, bean, null);

src/main/java/com/fasterxml/jackson/databind/deser/BasicDeserializerFactory.java

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -265,8 +265,8 @@ protected ValueInstantiator _constructDefaultValueInstantiator(DeserializationCo
265265
// 15-Mar-2015, tatu: Alas, this won't help with constructors that only have implicit
266266
// names. Those will need to be resolved later on.
267267
final CreatorCollector creators = new CreatorCollector(beanDesc, config);
268-
Map<AnnotatedWithParams,BeanPropertyDefinition[]> creatorDefs = _findCreatorsFromProperties(ctxt,
269-
beanDesc);
268+
Map<AnnotatedWithParams,BeanPropertyDefinition[]> creatorDefs =
269+
_findCreatorsFromProperties(beanDesc);
270270
ccState = new CreatorCollectionState(config, beanDesc, vchecker,
271271
creators, creatorDefs);
272272
}
@@ -307,7 +307,7 @@ protected ValueInstantiator _constructDefaultValueInstantiator(DeserializationCo
307307
return ccState.creators.constructValueInstantiator(ctxt);
308308
}
309309

310-
protected Map<AnnotatedWithParams,BeanPropertyDefinition[]> _findCreatorsFromProperties(DeserializationContext ctxt,
310+
protected Map<AnnotatedWithParams,BeanPropertyDefinition[]> _findCreatorsFromProperties(
311311
BeanDescription beanDesc) throws JsonMappingException
312312
{
313313
Map<AnnotatedWithParams,BeanPropertyDefinition[]> result = Collections.emptyMap();
@@ -327,9 +327,15 @@ protected Map<AnnotatedWithParams,BeanPropertyDefinition[]> _findCreatorsFromPro
327327
result.put(owner, defs);
328328
} else {
329329
if (defs[index] != null) {
330-
ctxt.reportBadTypeDefinition(beanDesc,
331-
"Conflict: parameter #%d of %s bound to more than one property; %s vs %s",
332-
index, owner, defs[index], propDef);
330+
// Inlined copy of "DeserializationContext.reportBadTypeDefinition()"
331+
String msg = String.format(
332+
"Conflict: parameter #%d of %s bound to more than one property; %s vs %s",
333+
index, owner, defs[index], propDef);
334+
String errorMsg =
335+
String.format("Invalid type definition for type %s: %s",
336+
ClassUtil.nameOf(beanDesc.getBeanClass()), msg);
337+
throw InvalidDefinitionException.from((JsonParser) null, errorMsg,
338+
beanDesc, null);
333339
}
334340
}
335341
defs[index] = propDef;

0 commit comments

Comments
 (0)