Skip to content

Commit

Permalink
Fix #1429
Browse files Browse the repository at this point in the history
  • Loading branch information
cowtowncoder committed Oct 25, 2016
1 parent 9257bd6 commit 9a66688
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 8 deletions.
2 changes: 2 additions & 0 deletions release-notes/VERSION
Expand Up @@ -7,6 +7,8 @@ Project: jackson-databind
2.8.5 (not yet released)

#1417: Further issues with `@JsonInclude` with `NON_DEFAULT`
#1429: `StdKeyDeserializer` can erroneously use a static factory method
with more than one argument
- Improvements to #1411 fix to ensure consistent `null` key handling

2.8.4 (14-Oct-2016)
Expand Down
Expand Up @@ -125,7 +125,8 @@ public Object deserializeKey(String key, DeserializationContext ctxt)
return result;
}
} catch (Exception re) {
return ctxt.handleWeirdKey(_keyClass, key, "not a valid representation, problem: %s", re.getMessage());
return ctxt.handleWeirdKey(_keyClass, key, "not a valid representation, problem: (%s) %s",
re.getClass().getName(), re.getMessage());
}
if (_keyClass.isEnum() && ctxt.getConfig().isEnabled(DeserializationFeature.READ_UNKNOWN_ENUM_VALUES_AS_NULL)) {
return null;
Expand Down
Expand Up @@ -521,7 +521,8 @@ public Method findFactoryMethod(Class<?>... expArgTypes)
{
// So, of all single-arg static methods:
for (AnnotatedMethod am : _classInfo.getStaticMethods()) {
if (isFactoryMethod(am)) {
// 24-Oct-2016, tatu: Better ensure it only takes 1 arg, no matter what
if (isFactoryMethod(am) && am.getParameterCount() == 1) {
// And must take one of expected arg types (or supertype)
Class<?> actualArgType = am.getRawParameterType(0);
for (Class<?> expArgType : expArgTypes) {
Expand All @@ -538,14 +539,12 @@ public Method findFactoryMethod(Class<?>... expArgTypes)
protected boolean isFactoryMethod(AnnotatedMethod am)
{
/* First: return type must be compatible with the introspected class
* (i.e. allowed to be sub-class, although usually is the same
* class)
* (i.e. allowed to be sub-class, although usually is the same class)
*/
Class<?> rt = am.getRawReturnType();
if (!getBeanClass().isAssignableFrom(rt)) {
return false;
}

/* Also: must be a recognized factory method, meaning:
* (a) marked with @JsonCreator annotation, or
* (b) "valueOf" (at this point, need not be public)
Expand All @@ -554,12 +553,15 @@ protected boolean isFactoryMethod(AnnotatedMethod am)
return true;
}
final String name = am.getName();
// 24-Oct-2016, tatu: As per [databind#1429] must ensure takes exactly one arg
if ("valueOf".equals(name)) {
return true;
if (am.getParameterCount() == 1) {
return true;
}
}
// [databind#208] Also accept "fromString()", if takes String or CharSequence
if ("fromString".equals(name)) {
if (1 == am.getParameterCount()) {
if (am.getParameterCount() == 1) {
Class<?> cls = am.getRawParameterType(0);
if (cls == String.class || CharSequence.class.isAssignableFrom(cls)) {
return true;
Expand Down
@@ -1,4 +1,4 @@
package com.fasterxml.jackson.failing;
package com.fasterxml.jackson.databind.deser;

import java.util.Map;

Expand Down

0 comments on commit 9a66688

Please sign in to comment.