diff --git a/src/main/java/com/fasterxml/jackson/databind/DatabindContext.java b/src/main/java/com/fasterxml/jackson/databind/DatabindContext.java index be2fd7d428..0ba5f7d65c 100644 --- a/src/main/java/com/fasterxml/jackson/databind/DatabindContext.java +++ b/src/main/java/com/fasterxml/jackson/databind/DatabindContext.java @@ -414,6 +414,12 @@ public T reportBadDefinition(Class type, String msg) throws JsonMappingEx return reportBadDefinition(constructType(type), msg); } + /** + * @since 2.18 + */ + public abstract T reportBadTypeDefinition(BeanDescription bean, + String msg, Object... msgArgs) throws JsonMappingException; + /* /********************************************************** /* Helper methods diff --git a/src/main/java/com/fasterxml/jackson/databind/DeserializationContext.java b/src/main/java/com/fasterxml/jackson/databind/DeserializationContext.java index 3dd858f537..108d1966df 100644 --- a/src/main/java/com/fasterxml/jackson/databind/DeserializationContext.java +++ b/src/main/java/com/fasterxml/jackson/databind/DeserializationContext.java @@ -1857,11 +1857,12 @@ public T reportTrailingTokens(Class targetType, * * @since 2.9 */ + @Override // since 2.18 public 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); } diff --git a/src/main/java/com/fasterxml/jackson/databind/SerializerProvider.java b/src/main/java/com/fasterxml/jackson/databind/SerializerProvider.java index 14db5ccde1..549291695c 100644 --- a/src/main/java/com/fasterxml/jackson/databind/SerializerProvider.java +++ b/src/main/java/com/fasterxml/jackson/databind/SerializerProvider.java @@ -1291,12 +1291,10 @@ public void reportMappingProblem(String message, Object... args) throws JsonMapp * * @since 2.9 */ + @Override // since 2.18 public 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); diff --git a/src/main/java/com/fasterxml/jackson/databind/deser/BasicDeserializerFactory.java b/src/main/java/com/fasterxml/jackson/databind/deser/BasicDeserializerFactory.java index 47d9a2c0dd..05efd8be9c 100644 --- a/src/main/java/com/fasterxml/jackson/databind/deser/BasicDeserializerFactory.java +++ b/src/main/java/com/fasterxml/jackson/databind/deser/BasicDeserializerFactory.java @@ -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 creatorDefs = _findCreatorsFromProperties(ctxt, - beanDesc); + Map creatorDefs = + _findCreatorsFromProperties(beanDesc); ccState = new CreatorCollectionState(config, beanDesc, vchecker, creators, creatorDefs); } @@ -307,7 +307,7 @@ protected ValueInstantiator _constructDefaultValueInstantiator(DeserializationCo return ccState.creators.constructValueInstantiator(ctxt); } - protected Map _findCreatorsFromProperties(DeserializationContext ctxt, + protected Map _findCreatorsFromProperties( BeanDescription beanDesc) throws JsonMappingException { Map result = Collections.emptyMap(); @@ -327,9 +327,15 @@ protected Map _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;