Skip to content

Commit 03fcbcc

Browse files
committed
Update findJsonValueType method to provide better support for Jackson < 2.9
1 parent a36f8b5 commit 03fcbcc

File tree

1 file changed

+20
-11
lines changed

1 file changed

+20
-11
lines changed

modules/swagger-core/src/main/java/io/swagger/v3/core/jackson/ModelResolver.java

Lines changed: 20 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1116,18 +1116,18 @@ protected Type findJsonValueType(final BeanDescription beanDesc) {
11161116

11171117
// use recursion to check for method findJsonValueAccessor existence (Jackson 2.9+)
11181118
// if not found use previous deprecated method which could lead to inaccurate result
1119-
try {
1120-
Method m = BeanDescription.class.getMethod("findJsonValueAccessor");
1121-
AnnotatedMember jsonValueMember = (AnnotatedMember)m.invoke(beanDesc);
1122-
if (jsonValueMember != null) {
1123-
return jsonValueMember.getType();
1124-
}
1125-
} catch (NoSuchMethodException | IllegalAccessException | InvocationTargetException e) {
1119+
AnnotatedMember jsonValueMember = invokeMethod(beanDesc, "findJsonValueAccessor");
1120+
if (jsonValueMember != null) {
1121+
return jsonValueMember.getType();
1122+
} else {
11261123
LOGGER.warn("jackson BeanDescription.findJsonValueAccessor not found, this could lead to inaccurate result, please update jackson to 2.9+");
1127-
final AnnotatedMethod jsonValueMethod = beanDesc.findJsonValueMethod();
1128-
if (jsonValueMethod != null) {
1129-
return jsonValueMethod.getType();
1130-
}
1124+
}
1125+
1126+
jsonValueMember = invokeMethod(beanDesc, "findJsonValueMethod");
1127+
if (jsonValueMember != null) {
1128+
return jsonValueMember.getType();
1129+
} else {
1130+
LOGGER.error("Neither 'findJsonValueMethod' nor 'findJsonValueAccessor' found in jackson BeanDescription. Please verify your Jackson version.");
11311131
}
11321132
return null;
11331133
}
@@ -3057,6 +3057,15 @@ protected boolean isNumberSchema(Schema schema){
30573057
return "number".equals(schema.getType()) || (schema.getTypes() != null && schema.getTypes().contains("number")) || "integer".equals(schema.getType()) || (schema.getTypes() != null && schema.getTypes().contains("integer"));
30583058
}
30593059

3060+
private AnnotatedMember invokeMethod(final BeanDescription beanDesc, String methodName) {
3061+
try {
3062+
Method m = BeanDescription.class.getMethod(methodName);
3063+
return (AnnotatedMember) m.invoke(beanDesc);
3064+
} catch (NoSuchMethodException | IllegalAccessException | InvocationTargetException e) {
3065+
return null;
3066+
}
3067+
}
3068+
30603069
protected Schema buildRefSchemaIfObject(Schema schema, ModelConverterContext context) {
30613070
if (schema == null) {
30623071
return null;

0 commit comments

Comments
 (0)