Skip to content

Commit 9269198

Browse files
committed
Merge branch '2.10'
2 parents 60e70e4 + f8738e8 commit 9269198

File tree

4 files changed

+67
-20
lines changed

4 files changed

+67
-20
lines changed

release-notes/VERSION-2.x

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ Project: jackson-databind
44
=== Releases ===
55
------------------------------------------------------------------------
66

7-
2.10.0-final (not yet released)
7+
2.10.0.pr3 (17-Sep-2019)
88

99
#1093: Default typing does not work with `writerFor(Object.class)`
1010
(reported by hoomanv@github)

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

Lines changed: 31 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -848,7 +848,7 @@ public Calendar constructCalendar(Date d) {
848848
/* Convenience methods for reading parsed values
849849
/**********************************************************************
850850
*/
851-
851+
852852
/**
853853
* Convenience method that may be used by composite or container deserializers,
854854
* for reading one-off values for the composite type, taking into account
@@ -865,7 +865,7 @@ public <T> T readPropertyValue(JsonParser p, BeanProperty prop, JavaType type) t
865865
if (deser == null) {
866866
return reportBadDefinition(type, String.format(
867867
"Could not find JsonDeserializer for type %s (via property %s)",
868-
type, ClassUtil.nameOf(prop)));
868+
ClassUtil.getTypeDescription(type), ClassUtil.nameOf(prop)));
869869
}
870870
return (T) deser.deserialize(p, this);
871871
}
@@ -942,7 +942,9 @@ public Object handleWeirdKey(Class<?> keyClass, String keyValue,
942942
}
943943
throw weirdStringException(keyValue, keyClass, String.format(
944944
"DeserializationProblemHandler.handleWeirdStringValue() for type %s returned value of type %s",
945-
keyClass, key.getClass()));
945+
ClassUtil.getClassDescription(keyClass),
946+
ClassUtil.getClassDescription(key)
947+
));
946948
}
947949
h = h.next();
948950
}
@@ -984,7 +986,9 @@ public Object handleWeirdStringValue(Class<?> targetClass, String value,
984986
}
985987
throw weirdStringException(value, targetClass, String.format(
986988
"DeserializationProblemHandler.handleWeirdStringValue() for type %s returned value of type %s",
987-
targetClass, instance.getClass()));
989+
ClassUtil.getClassDescription(targetClass),
990+
ClassUtil.getClassDescription(instance)
991+
));
988992
}
989993
h = h.next();
990994
}
@@ -1025,7 +1029,9 @@ public Object handleWeirdNumberValue(Class<?> targetClass, Number value,
10251029
}
10261030
throw weirdNumberException(value, targetClass, _format(
10271031
"DeserializationProblemHandler.handleWeirdNumberValue() for type %s returned value of type %s",
1028-
targetClass, key.getClass()));
1032+
ClassUtil.getClassDescription(targetClass),
1033+
ClassUtil.getClassDescription(key)
1034+
));
10291035
}
10301036
h = h.next();
10311037
}
@@ -1048,7 +1054,9 @@ public Object handleWeirdNativeValue(JavaType targetType, Object badValue,
10481054
}
10491055
throw JsonMappingException.from(p, _format(
10501056
"DeserializationProblemHandler.handleWeirdNativeValue() for type %s returned value of type %s",
1051-
targetType, goodValue.getClass()));
1057+
ClassUtil.getClassDescription(targetType),
1058+
ClassUtil.getClassDescription(goodValue)
1059+
));
10521060
}
10531061
}
10541062
throw weirdNativeValueException(badValue, raw);
@@ -1090,7 +1098,9 @@ public Object handleMissingInstantiator(Class<?> instClass, ValueInstantiator va
10901098
}
10911099
reportBadDefinition(constructType(instClass), String.format(
10921100
"DeserializationProblemHandler.handleMissingInstantiator() for type %s returned value of type %s",
1093-
instClass, ClassUtil.classNameOf(instance)));
1101+
ClassUtil.getClassDescription(instClass),
1102+
ClassUtil.getClassDescription((instance)
1103+
)));
10941104
}
10951105
h = h.next();
10961106
}
@@ -1138,7 +1148,9 @@ public Object handleInstantiationProblem(Class<?> instClass, Object argument,
11381148
}
11391149
reportBadDefinition(constructType(instClass), String.format(
11401150
"DeserializationProblemHandler.handleInstantiationProblem() for type %s returned value of type %s",
1141-
instClass, ClassUtil.classNameOf(instance)));
1151+
ClassUtil.getClassDescription(instClass),
1152+
ClassUtil.classNameOf(instance)
1153+
));
11421154
}
11431155
h = h.next();
11441156
}
@@ -1213,17 +1225,19 @@ public Object handleUnexpectedToken(JavaType targetType, JsonToken t,
12131225
}
12141226
reportBadDefinition(targetType, String.format(
12151227
"DeserializationProblemHandler.handleUnexpectedToken() for type %s returned value of type %s",
1216-
targetType, ClassUtil.classNameOf(instance)));
1228+
ClassUtil.getClassDescription(targetType),
1229+
ClassUtil.classNameOf(instance)
1230+
));
12171231
}
12181232
h = h.next();
12191233
}
12201234
if (msg == null) {
12211235
if (t == null) {
12221236
msg = String.format("Unexpected end-of-input when binding data into %s",
1223-
targetType);
1237+
ClassUtil.getTypeDescription(targetType));
12241238
} else {
12251239
msg = String.format("Cannot deserialize value of type %s out of %s token",
1226-
targetType, t);
1240+
ClassUtil.getTypeDescription(targetType), t);
12271241
}
12281242
}
12291243
reportInputMismatch(targetType, msg);
@@ -1264,7 +1278,8 @@ public JavaType handleUnknownTypeId(JavaType baseType, String id,
12641278
return type;
12651279
}
12661280
throw invalidTypeIdException(baseType, id,
1267-
"problem handler tried to resolve into non-subtype: "+type);
1281+
"problem handler tried to resolve into non-subtype: "+
1282+
ClassUtil.getTypeDescription(type));
12681283
}
12691284
h = h.next();
12701285
}
@@ -1291,7 +1306,8 @@ public JavaType handleMissingTypeId(JavaType baseType,
12911306
return type;
12921307
}
12931308
throw invalidTypeIdException(baseType, null,
1294-
"problem handler tried to resolve into non-subtype: "+type);
1309+
"problem handler tried to resolve into non-subtype: "+
1310+
ClassUtil.getTypeDescription(type));
12951311
}
12961312
h = h.next();
12971313
}
@@ -1316,7 +1332,8 @@ public void handleBadMerge(JsonDeserializer<?> deser) throws JsonMappingExceptio
13161332
{
13171333
if (!isEnabled(MapperFeature.IGNORE_MERGE_FOR_UNMERGEABLE)) {
13181334
JavaType type = constructType(deser.handledType());
1319-
String msg = String.format("Invalid configuration: values of type %s cannot be merged", type);
1335+
String msg = String.format("Invalid configuration: values of type %s cannot be merged",
1336+
ClassUtil.getTypeDescription(type));
13201337
throw InvalidDefinitionException.from(getParser(), msg, type);
13211338
}
13221339
}

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

Lines changed: 23 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -584,7 +584,7 @@ public static String quotedOr(Object str, String forNull) {
584584
/* Type name, name, desc handling methods
585585
/**********************************************************
586586
*/
587-
587+
588588
/**
589589
* Helper method used to construct appropriate description
590590
* when passed either type (Class) or an instance; in latter
@@ -600,6 +600,27 @@ public static String getClassDescription(Object classOrInstance)
600600
return nameOf(cls);
601601
}
602602

603+
/**
604+
* Helper method to create and return "backticked" description of given
605+
* resolved type (or, {@code "null"} if {@code null} passed), similar
606+
* to return vaue of {@link #getClassDescription(Object)}.
607+
*
608+
* @param type Fully resolved type or null
609+
* @return String description of type including generic type parameters, surrounded
610+
* by backticks, if type passed; or string "null" if {code null} passed
611+
*
612+
* @since 2.10
613+
*/
614+
public static String getTypeDescription(JavaType fullType)
615+
{
616+
if (fullType == null) {
617+
return "[null]";
618+
}
619+
StringBuilder sb = new StringBuilder(80).append('`');
620+
sb.append(fullType.toCanonical());
621+
return sb.append('`').toString();
622+
}
623+
603624
/**
604625
* Helper method used to construct appropriate description
605626
* when passed either type (Class) or an instance; in latter
@@ -654,7 +675,7 @@ public static String nameOf(Named named) {
654675

655676
/*
656677
/**********************************************************
657-
/* Other escaping, description acces
678+
/* Other escaping, description access
658679
/**********************************************************
659680
*/
660681

src/test/java/com/fasterxml/jackson/databind/util/ClassUtilTest.java

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,10 @@
22

33
import java.util.*;
44

5+
import com.fasterxml.jackson.core.type.TypeReference;
56
import com.fasterxml.jackson.databind.BaseMapTest;
7+
import com.fasterxml.jackson.databind.JavaType;
8+
import com.fasterxml.jackson.databind.type.TypeFactory;
69
import com.fasterxml.jackson.databind.util.ClassUtil;
710

811
public class ClassUtilTest extends BaseMapTest
@@ -196,8 +199,14 @@ public void testFindEnumType()
196199

197200
public void testDescs()
198201
{
199-
final String exp = "`java.lang.String`";
200-
assertEquals(exp, ClassUtil.getClassDescription("foo"));
201-
assertEquals(exp, ClassUtil.getClassDescription(String.class));
202+
final String stringExp = "`java.lang.String`";
203+
assertEquals(stringExp, ClassUtil.getClassDescription("foo"));
204+
assertEquals(stringExp, ClassUtil.getClassDescription(String.class));
205+
final JavaType stringType = TypeFactory.defaultInstance().constructType(String.class);
206+
assertEquals(stringExp, ClassUtil.getTypeDescription(stringType));
207+
final JavaType mapType = TypeFactory.defaultInstance().constructType(
208+
new TypeReference<Map<String, Integer>>() { });
209+
assertEquals("`java.util.Map<java.lang.String,java.lang.Integer>`",
210+
ClassUtil.getTypeDescription(mapType));
202211
}
203212
}

0 commit comments

Comments
 (0)