Skip to content

Commit 5de7428

Browse files
committed
Minor refactoring wrt #2632
1 parent 337144e commit 5de7428

File tree

4 files changed

+20
-11
lines changed

4 files changed

+20
-11
lines changed

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

+4-8
Original file line numberDiff line numberDiff line change
@@ -153,15 +153,11 @@ public JavaType constructType(Type type) {
153153

154154
/**
155155
* Convenience method for constructing subtypes, retaining generic
156-
* type parameter (if any)
156+
* type parameter (if any).
157+
*<p>
158+
* Note: since 2.11 handling has varied a bit across serialization, deserialization.
157159
*/
158-
public JavaType constructSpecializedType(JavaType baseType, Class<?> subclass) {
159-
// simple optimization to avoid costly introspection if type-erased type does NOT differ
160-
if (baseType.getRawClass() == subclass) {
161-
return baseType;
162-
}
163-
return getConfig().constructSpecializedType(baseType, subclass);
164-
}
160+
public abstract JavaType constructSpecializedType(JavaType baseType, Class<?> subclass);
165161

166162
/**
167163
* Lookup method called when code needs to resolve class name from input;

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

+7
Original file line numberDiff line numberDiff line change
@@ -252,6 +252,13 @@ public final TypeFactory getTypeFactory() {
252252
return _config.getTypeFactory();
253253
}
254254

255+
@Override // since 2.11
256+
public JavaType constructSpecializedType(JavaType baseType, Class<?> subclass) {
257+
// No specialized handling for deserialization, but needs to be implemented
258+
return baseType.hasRawClass(subclass) ? baseType
259+
: getConfig().constructSpecializedType(baseType, subclass);
260+
}
261+
255262
/**
256263
* Method for accessing default Locale to use: convenience method for
257264
*<pre>

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

+8-2
Original file line numberDiff line numberDiff line change
@@ -313,8 +313,7 @@ public void setNullKeySerializer(JsonSerializer<Object> nks)
313313

314314
/*
315315
/**********************************************************
316-
/* DatabindContext implementation (and closely related
317-
/* but ser-specific)
316+
/* DatabindContext implementation (and closely related but ser-specific)
318317
/**********************************************************
319318
*/
320319

@@ -334,6 +333,13 @@ public final TypeFactory getTypeFactory() {
334333
return _config.getTypeFactory();
335334
}
336335

336+
@Override // since 2.11
337+
public JavaType constructSpecializedType(JavaType baseType, Class<?> subclass) {
338+
// Need little bit different handling due to [databind#2632]
339+
return baseType.hasRawClass(subclass) ? baseType
340+
: getConfig().constructSpecializedType(baseType, subclass);
341+
}
342+
337343
@Override
338344
public final Class<?> getActiveView() { return _serializationView; }
339345

src/test/java/com/fasterxml/jackson/databind/jsontype/SubTypeResolutionTest.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -139,7 +139,7 @@ public void testSpecializeIncompatibleRawType() throws Exception
139139
assertNotNull(json);
140140
fail("Should not (yet?) pass");
141141
} catch (JsonMappingException e) {
142-
verifyException(e, "Failed to specialize base type ");
142+
verifyException(e, "Failed to specialize base type ");
143143
}
144144
}
145145
}

0 commit comments

Comments
 (0)