Skip to content

Commit bb06aa0

Browse files
committed
More error reporting improvements to track down #1342
1 parent 46255d3 commit bb06aa0

File tree

4 files changed

+52
-2
lines changed

4 files changed

+52
-2
lines changed

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

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
import com.fasterxml.jackson.databind.exc.InvalidTypeIdException;
2020
import com.fasterxml.jackson.databind.exc.UnrecognizedPropertyException;
2121
import com.fasterxml.jackson.databind.introspect.Annotated;
22+
import com.fasterxml.jackson.databind.introspect.BeanPropertyDefinition;
2223
import com.fasterxml.jackson.databind.jsontype.TypeDeserializer;
2324
import com.fasterxml.jackson.databind.jsontype.TypeIdResolver;
2425
import com.fasterxml.jackson.databind.node.JsonNodeFactory;
@@ -1258,6 +1259,41 @@ public void reportUnresolvedObjectId(ObjectIdReader oidReader, Object bean)
12581259
throw JsonMappingException.from(getParser(), msg);
12591260
}
12601261

1262+
/**
1263+
* Helper method called to indicate problem in POJO (serialization) definitions or settings
1264+
* regarding specific Java type, unrelated to actual JSON content to map.
1265+
* Default behavior is to construct and throw a {@link JsonMappingException}.
1266+
*
1267+
* @since 2.9
1268+
*/
1269+
public <T> T reportBadTypeDefinition(BeanDescription bean,
1270+
String message, Object... args) throws JsonMappingException {
1271+
if (args != null && args.length > 0) {
1272+
message = String.format(message, args);
1273+
}
1274+
String beanDesc = (bean == null) ? "N/A" : _desc(bean.getType().getGenericSignature());
1275+
throw mappingException("Invalid type definition for type %s: %s",
1276+
beanDesc, message);
1277+
}
1278+
1279+
/**
1280+
* Helper method called to indicate problem in POJO (serialization) definitions or settings
1281+
* regarding specific property (of a type), unrelated to actual JSON content to map.
1282+
* Default behavior is to construct and throw a {@link JsonMappingException}.
1283+
*
1284+
* @since 2.9
1285+
*/
1286+
public <T> T reportBadPropertyDefinition(BeanDescription bean, BeanPropertyDefinition prop,
1287+
String message, Object... args) throws JsonMappingException {
1288+
if (args != null && args.length > 0) {
1289+
message = String.format(message, args);
1290+
}
1291+
String propName = (prop == null) ? "N/A" : _quotedString(prop.getName());
1292+
String beanDesc = (bean == null) ? "N/A" : _desc(bean.getType().getGenericSignature());
1293+
throw mappingException("Invalid definition for property %s (of type %s): %s",
1294+
propName, beanDesc, message);
1295+
}
1296+
12611297
/*
12621298
/**********************************************************
12631299
/* Methods for constructing exceptions, "untyped"

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ public enum MapperFeature implements ConfigFeature
2121
/* Introspection features
2222
/******************************************************
2323
*/
24-
24+
2525
/**
2626
* Feature that determines whether annotation introspection
2727
* is used for configuration; if enabled, configured

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

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1175,7 +1175,7 @@ public <T> T reportBadPropertyDefinition(BeanDescription bean, BeanPropertyDefin
11751175
if (args != null && args.length > 0) {
11761176
message = String.format(message, args);
11771177
}
1178-
String propName = (prop == null) ? "N/A" : _desc(prop.getName());
1178+
String propName = (prop == null) ? "N/A" : _quotedString(prop.getName());
11791179
String beanDesc = (bean == null) ? "N/A" : _desc(bean.getType().getGenericSignature());
11801180
throw mappingException("Invalid definition for property %s (of type %s): %s",
11811181
propName, beanDesc, message);
@@ -1347,6 +1347,13 @@ protected String _desc(Object value) {
13471347
return "'"+value+"'";
13481348
}
13491349

1350+
protected String _quotedString(Object value) {
1351+
if (value == null) {
1352+
return "N/A";
1353+
}
1354+
return String.valueOf(value);
1355+
}
1356+
13501357
protected final DateFormat _dateFormat()
13511358
{
13521359
if (_dateFormat != null) {

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

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -719,6 +719,12 @@ protected SettableBeanProperty constructSettableProperty(DeserializationContext
719719
{
720720
// need to ensure method is callable (for non-public)
721721
AnnotatedMember mutator = propDef.getNonConstructorMutator();
722+
// 08-Sep-2016, tatu: issues like [databind#1342] suggest something fishy
723+
// going on; add sanity checks to try to pin down actual problem...
724+
// Possibly passing creator parameter?
725+
if (mutator == null) {
726+
ctxt.reportBadPropertyDefinition(beanDesc, propDef, "No non-constructor mutator available");
727+
}
722728
JavaType type = resolveMemberAndTypeAnnotations(ctxt, mutator, propType0);
723729
// Does the Method specify the deserializer to use? If so, let's use it.
724730
TypeDeserializer typeDeser = type.getTypeHandler();
@@ -727,6 +733,7 @@ protected SettableBeanProperty constructSettableProperty(DeserializationContext
727733
prop = new MethodProperty(propDef, type, typeDeser,
728734
beanDesc.getClassAnnotations(), (AnnotatedMethod) mutator);
729735
} else {
736+
// 08-Sep-2016, tatu: wonder if we should verify it is `AnnotatedField` to be safe?
730737
prop = new FieldProperty(propDef, type, typeDeser,
731738
beanDesc.getClassAnnotations(), (AnnotatedField) mutator);
732739
}

0 commit comments

Comments
 (0)