Skip to content

Commit 3b041e3

Browse files
committed
Fix #667
1 parent a399c54 commit 3b041e3

File tree

3 files changed

+33
-3
lines changed

3 files changed

+33
-3
lines changed

release-notes/VERSION

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,10 @@ Project: jackson-databind
44
=== Releases ===
55
------------------------------------------------------------------------
66

7+
2.5.1 (not yet released)
8+
9+
#667: Problem with bogus conflict between single-arg-String vs `CharSequence` constructor
10+
711
2.5.0 (01-Jan-2015)
812

913
#47: Support `@JsonValue` for (Map) key serialization

src/main/java/com/fasterxml/jackson/databind/deser/impl/CreatorCollector.java

Lines changed: 23 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -280,16 +280,36 @@ protected void verifyNonDup(AnnotatedWithParams newOne, int typeIndex, boolean e
280280
AnnotatedWithParams oldOne = _creators[typeIndex];
281281
// already had an explicitly marked one?
282282
if (oldOne != null) {
283+
boolean verify;
284+
283285
if ((_explicitCreators & mask) != 0) { // already had explicitly annotated, leave as-is
284286
// but skip, if new one not annotated
285287
if (!explicit) {
286288
return;
287289
}
290+
// both explicit: verify
291+
verify = true;
292+
} else {
293+
// otherwise only verify if neither explicitly annotated.
294+
verify = !explicit;
288295
}
296+
289297
// one more thing: ok to override in sub-class
290-
if (oldOne.getClass() == newOne.getClass()) {
291-
throw new IllegalArgumentException("Conflicting "+TYPE_DESCS[typeIndex]
292-
+" creators: already had explicitly marked "+oldOne+", encountered "+newOne);
298+
if (verify && (oldOne.getClass() == newOne.getClass())) {
299+
// [databind#667]: avoid one particular class of bogus problems
300+
Class<?> oldType = oldOne.getRawParameterType(0);
301+
Class<?> newType = newOne.getRawParameterType(0);
302+
303+
if (oldType == newType) {
304+
throw new IllegalArgumentException("Conflicting "+TYPE_DESCS[typeIndex]
305+
+" creators: already had explicitly marked "+oldOne+", encountered "+newOne);
306+
}
307+
// otherwise, which one to choose?
308+
if (newType.isAssignableFrom(oldType)) {
309+
// new type more generic, use old
310+
return;
311+
}
312+
// new type more specific, use it
293313
}
294314
}
295315
if (explicit) {

src/test/java/com/fasterxml/jackson/databind/deser/TestJdkTypes.java

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -420,6 +420,12 @@ public void testByteBuffer() throws Exception
420420
assertEquals(0, result.remaining());
421421
}
422422

423+
public void testStringBuilder() throws Exception
424+
{
425+
StringBuilder sb = MAPPER.readValue(quote("abc"), StringBuilder.class);
426+
assertEquals("abc", sb.toString());
427+
}
428+
423429
// [Issue#429]
424430
public void testStackTraceElementWithCustom() throws Exception
425431
{

0 commit comments

Comments
 (0)