Skip to content

Commit 489659c

Browse files
committed
more test coverage
1 parent 8928f0c commit 489659c

14 files changed

+199
-129
lines changed

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

Lines changed: 80 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,15 @@
2525
*/
2626
public abstract class DatabindContext
2727
{
28+
/**
29+
* Let's limit length of error messages, for cases where underlying data
30+
* may be very large -- no point in spamming logs with megabytes of meaningless
31+
* data.
32+
*
33+
* @since 2.9
34+
*/
35+
private final static int MAX_ERROR_STR_LEN = 500;
36+
2837
/*
2938
/**********************************************************
3039
/* Generic config access
@@ -250,4 +259,75 @@ public Converter<Object,Object> converterInstance(Annotated annotated,
250259
public <T> T reportBadDefinition(Class<?> type, String msg) throws JsonMappingException {
251260
return reportBadDefinition(constructType(type), msg);
252261
}
262+
263+
/*
264+
/**********************************************************
265+
/* Helper methods
266+
/**********************************************************
267+
*/
268+
269+
/**
270+
* @since 2.9
271+
*/
272+
protected final String _format(String msg, Object... msgArgs) {
273+
if (msgArgs.length > 0) {
274+
return String.format(msg, msgArgs);
275+
}
276+
return msg;
277+
}
278+
279+
/**
280+
* @since 2.9
281+
*/
282+
protected final String _truncate(String desc) {
283+
if (desc == null) {
284+
return "";
285+
}
286+
if (desc.length() <= MAX_ERROR_STR_LEN) {
287+
return desc;
288+
}
289+
return desc.substring(0, MAX_ERROR_STR_LEN) + "]...[" + desc.substring(desc.length() - MAX_ERROR_STR_LEN);
290+
}
291+
292+
/**
293+
* @since 2.9
294+
*/
295+
protected String _quotedString(String desc) {
296+
if (desc == null) {
297+
return "[N/A]";
298+
}
299+
// !!! should we quote it? (in case there are control chars, linefeeds)
300+
return String.format("\"%s\"", _truncate(desc));
301+
}
302+
303+
/**
304+
* @since 2.9
305+
*/
306+
protected String _colonConcat(String msgBase, String extra) {
307+
if (extra == null) {
308+
return msgBase;
309+
}
310+
return msgBase + ": " + extra;
311+
}
312+
313+
/**
314+
* @since 2.9
315+
*/
316+
protected String _calcName(Class<?> cls) {
317+
if (cls.isArray()) {
318+
return _calcName(cls.getComponentType())+"[]";
319+
}
320+
return cls.getName();
321+
}
322+
323+
/**
324+
* @since 2.9
325+
*/
326+
protected String _desc(String desc) {
327+
if (desc == null) {
328+
return "[N/A]";
329+
}
330+
// !!! should we quote it? (in case there are control chars, linefeeds)
331+
return _truncate(desc);
332+
}
253333
}

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

Lines changed: 0 additions & 63 deletions
Original file line numberDiff line numberDiff line change
@@ -53,13 +53,6 @@ public abstract class DeserializationContext
5353
{
5454
private static final long serialVersionUID = 1L; // 2.6
5555

56-
/**
57-
* Let's limit length of error messages, for cases where underlying data
58-
* may be very large -- no point in spamming logs with megs of meaningless
59-
* data.
60-
*/
61-
private final static int MAX_ERROR_STR_LEN = 500;
62-
6356
/*
6457
/**********************************************************
6558
/* Configuration, immutable
@@ -1681,60 +1674,4 @@ protected DateFormat getDateFormat()
16811674
_dateFormat = df = (DateFormat) df.clone();
16821675
return df;
16831676
}
1684-
1685-
protected String _calcName(Class<?> cls) {
1686-
if (cls.isArray()) {
1687-
return _calcName(cls.getComponentType())+"[]";
1688-
}
1689-
return cls.getName();
1690-
}
1691-
1692-
protected String _valueDesc() {
1693-
try {
1694-
return _desc(_parser.getText());
1695-
} catch (Exception e) {
1696-
return "[N/A]";
1697-
}
1698-
}
1699-
1700-
protected String _desc(String desc) {
1701-
if (desc == null) {
1702-
return "[N/A]";
1703-
}
1704-
// !!! should we quote it? (in case there are control chars, linefeeds)
1705-
if (desc.length() > MAX_ERROR_STR_LEN) {
1706-
desc = desc.substring(0, MAX_ERROR_STR_LEN) + "]...[" + desc.substring(desc.length() - MAX_ERROR_STR_LEN);
1707-
}
1708-
return desc;
1709-
}
1710-
1711-
// @since 2.7
1712-
protected String _quotedString(String desc) {
1713-
if (desc == null) {
1714-
return "[N/A]";
1715-
}
1716-
// !!! should we quote it? (in case there are control chars, linefeeds)
1717-
if (desc.length() > MAX_ERROR_STR_LEN) {
1718-
return String.format("\"%s]...[%s\"",
1719-
desc.substring(0, MAX_ERROR_STR_LEN),
1720-
desc.substring(desc.length() - MAX_ERROR_STR_LEN));
1721-
}
1722-
return String.format("\"%s\"", desc);
1723-
}
1724-
1725-
// @since 2.9
1726-
protected String _colonConcat(String msgBase, String extra) {
1727-
if (extra == null) {
1728-
return msgBase;
1729-
}
1730-
return msgBase + ": " + extra;
1731-
}
1732-
1733-
// @since 2.9
1734-
protected String _format(String msg, Object... msgArgs) {
1735-
if (msgArgs.length > 0) {
1736-
return String.format(msg, msgArgs);
1737-
}
1738-
return msg;
1739-
}
17401677
}

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ public Object findInjectableValue(Object valueId, DeserializationContext ctxt,
7171
ctxt.reportBadDefinition(ClassUtil.classOf(valueId),
7272
String.format(
7373
"Unrecognized inject value id type (%s), expecting String",
74-
ClassUtil.classNameOf(valueId, "[null]")));
74+
ClassUtil.classNameOf(valueId)));
7575
}
7676
String key = (String) valueId;
7777
Object ob = _values.get(key);

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

Lines changed: 0 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1404,20 +1404,6 @@ protected JsonSerializer<Object> _handleResolvable(JsonSerializer<?> ser)
14041404
/**********************************************************
14051405
*/
14061406

1407-
protected String _desc(Object value) {
1408-
if (value == null) {
1409-
return "N/A";
1410-
}
1411-
return "'"+value+"'";
1412-
}
1413-
1414-
protected String _quotedString(Object value) {
1415-
if (value == null) {
1416-
return "N/A";
1417-
}
1418-
return String.valueOf(value);
1419-
}
1420-
14211407
protected final DateFormat _dateFormat()
14221408
{
14231409
if (_dateFormat != null) {
@@ -1439,12 +1425,4 @@ protected final DateFormat _dateFormat()
14391425
*/
14401426
return df;
14411427
}
1442-
1443-
// @since 2.9
1444-
protected String _format(String msg, Object... msgArgs) {
1445-
if (msgArgs.length > 0) {
1446-
return String.format(msg, msgArgs);
1447-
}
1448-
return msg;
1449-
}
14501428
}

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -551,7 +551,7 @@ protected void addBeanProps(DeserializationContext ctxt,
551551
if (cprop == null) {
552552
ctxt.reportBadTypeDefinition(beanDesc,
553553
"Could not find creator property with name '%s' (in class %s)",
554-
name, beanDesc.getBeanClass().getName());
554+
name, ClassUtil.classNameOf(beanDesc.getBeanClass()));
555555
continue;
556556
}
557557
if (prop != null) {

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -195,7 +195,7 @@ protected void _throwAsIOE(Exception e, Object propName, Object value)
195195
throws IOException
196196
{
197197
if (e instanceof IllegalArgumentException) {
198-
String actType = ClassUtil.classNameOf(value, "[NULL]");
198+
String actType = ClassUtil.classNameOf(value);
199199
StringBuilder msg = new StringBuilder("Problem deserializing \"any\" property '").append(propName);
200200
msg.append("' of class "+getClassName()+" (expected type: ").append(_type);
201201
msg.append("; actual type: ").append(actType).append(")");

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -522,7 +522,7 @@ public final Object deserializeWith(JsonParser p, DeserializationContext ctxt,
522522
protected void _throwAsIOE(JsonParser p, Exception e, Object value) throws IOException
523523
{
524524
if (e instanceof IllegalArgumentException) {
525-
String actType = ClassUtil.classNameOf(value, "[NULL]");
525+
String actType = ClassUtil.classNameOf(value);
526526
StringBuilder msg = new StringBuilder("Problem deserializing property '").append(getName());
527527
msg.append("' (expected type: ").append(getType());
528528
msg.append("; actual type: ").append(actType).append(")");

src/main/java/com/fasterxml/jackson/databind/ser/DefaultSerializerProvider.java

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -605,9 +605,6 @@ public void acceptJsonFormatVisitor(JavaType javaType, JsonFormatVisitorWrapper
605605
public com.fasterxml.jackson.databind.jsonschema.JsonSchema generateJsonSchema(Class<?> type)
606606
throws JsonMappingException
607607
{
608-
if (type == null) {
609-
throw new IllegalArgumentException("A class must be provided");
610-
}
611608
/* no need for embedded type information for JSON schema generation (all
612609
* type information it needs is accessible via "untyped" serializer)
613610
*/

src/main/java/com/fasterxml/jackson/databind/util/ClassUtil.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -662,9 +662,9 @@ public static boolean hasClass(Object inst, Class<?> raw) {
662662
/**
663663
* @since 2.9
664664
*/
665-
public static String classNameOf(Object inst, String defName) {
665+
public static String classNameOf(Object inst) {
666666
if (inst == null) {
667-
return defName;
667+
return "[null]";
668668
}
669669
return inst.getClass().getName();
670670
}

src/main/java/com/fasterxml/jackson/databind/util/RawValue.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -119,6 +119,6 @@ public int hashCode() {
119119

120120
@Override
121121
public String toString() {
122-
return String.format("[RawValue of type %s]", ClassUtil.classNameOf(_value, "NULL"));
122+
return String.format("[RawValue of type %s]", ClassUtil.classNameOf(_value));
123123
}
124124
}

0 commit comments

Comments
 (0)