16
16
public class ClassNameIdResolver
17
17
extends TypeIdResolverBase
18
18
{
19
+ private final static String JAVA_UTIL_PKG = "java.util." ;
20
+
19
21
public ClassNameIdResolver (JavaType baseType , TypeFactory typeFactory ) {
20
22
super (baseType , typeFactory );
21
23
}
@@ -70,7 +72,7 @@ protected String _idFrom(Object value, Class<?> cls, TypeFactory typeFactory)
70
72
}
71
73
}
72
74
String str = cls .getName ();
73
- if (str .startsWith ("java.util." )) {
75
+ if (str .startsWith (JAVA_UTIL_PKG )) {
74
76
// 25-Jan-2009, tatu: There are some internal classes that we cannot access as is.
75
77
// We need better mechanism; for now this has to do...
76
78
@@ -90,12 +92,12 @@ protected String _idFrom(Object value, Class<?> cls, TypeFactory typeFactory)
90
92
// 17-Feb-2010, tatus: Another such case: result of Arrays.asList() is
91
93
// named like so in Sun JDK... Let's just plain old ArrayList in its place.
92
94
// ... also, other similar cases exist...
93
- String suffix = str .substring (10 );
95
+ String suffix = str .substring (JAVA_UTIL_PKG . length () );
94
96
if (isJavaUtilCollectionClass (suffix , "List" )) {
95
97
str = ArrayList .class .getName ();
96
- } else if (isJavaUtilCollectionClass (suffix , "Map" )){
98
+ } else if (isJavaUtilCollectionClass (suffix , "Map" )){
97
99
str = HashMap .class .getName ();
98
- } else if (isJavaUtilCollectionClass (suffix , "Set" )){
100
+ } else if (isJavaUtilCollectionClass (suffix , "Set" )){
99
101
str = HashSet .class .getName ();
100
102
}
101
103
}
@@ -109,10 +111,8 @@ protected String _idFrom(Object value, Class<?> cls, TypeFactory typeFactory)
109
111
*/
110
112
Class <?> outer = ClassUtil .getOuterClass (cls );
111
113
if (outer != null ) {
112
- /* one more check: let's actually not worry if the declared
113
- * static type is non-static as well; if so, deserializer does
114
- * have a chance at figuring it all out.
115
- */
114
+ // one more check: let's actually not worry if the declared static type is
115
+ // non-static as well; if so, deserializer does have a chance at figuring it all out.
116
116
Class <?> staticType = _baseType .getRawClass ();
117
117
if (ClassUtil .getOuterClass (staticType ) == null ) {
118
118
// Is this always correct? Seems like it should be...
@@ -129,8 +129,16 @@ public String getDescForKnownTypeIds() {
129
129
return "class name used as type id" ;
130
130
}
131
131
132
- private static boolean isJavaUtilCollectionClass (String clz , String type ){
133
- return (clz .startsWith ("Collections$" ) || clz .startsWith ("Arrays$" ))
134
- && clz .indexOf (type ) > 0 ;
132
+ private static boolean isJavaUtilCollectionClass (String clz , String type )
133
+ {
134
+ if (clz .startsWith ("Collections$" )) {
135
+ // 02-Jan-2017, tatu: As per [databind#1868], need to leave Unmodifiable variants as is
136
+ return ((clz .indexOf (type ) > 0 )
137
+ && !clz .contains ("Unmodifiable" ));
138
+ }
139
+ if (clz .startsWith ("Arrays$" )) {
140
+ return (clz .indexOf (type ) > 0 );
141
+ }
142
+ return false ;
135
143
}
136
144
}
0 commit comments