Skip to content

Commit 7d5ec61

Browse files
committed
fix findJsonValueType
1 parent affcb1d commit 7d5ec61

File tree

1 file changed

+15
-15
lines changed

1 file changed

+15
-15
lines changed

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

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1116,17 +1116,21 @@ 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-
AnnotatedMember jsonValueMember = invokeMethod(beanDesc, "findJsonValueAccessor");
1120-
if (jsonValueMember != null) {
1121-
return jsonValueMember.getType();
1122-
} else {
1119+
try {
1120+
AnnotatedMember jsonValueMember = invokeMethod(beanDesc, "findJsonValueAccessor");
1121+
if (jsonValueMember != null) {
1122+
return jsonValueMember.getType();
1123+
}
1124+
} catch (Exception e) {
11231125
LOGGER.warn("jackson BeanDescription.findJsonValueAccessor not found, this could lead to inaccurate result, please update jackson to 2.9+");
11241126
}
11251127

1126-
jsonValueMember = invokeMethod(beanDesc, "findJsonValueMethod");
1127-
if (jsonValueMember != null) {
1128-
return jsonValueMember.getType();
1129-
} else {
1128+
try {
1129+
AnnotatedMember jsonValueMember = invokeMethod(beanDesc, "findJsonValueMethod");
1130+
if (jsonValueMember != null) {
1131+
return jsonValueMember.getType();
1132+
}
1133+
} catch (Exception e) {
11301134
LOGGER.error("Neither 'findJsonValueMethod' nor 'findJsonValueAccessor' found in jackson BeanDescription. Please verify your Jackson version.");
11311135
}
11321136
return null;
@@ -3057,13 +3061,9 @@ protected boolean isNumberSchema(Schema schema){
30573061
return "number".equals(schema.getType()) || (schema.getTypes() != null && schema.getTypes().contains("number")) || "integer".equals(schema.getType()) || (schema.getTypes() != null && schema.getTypes().contains("integer"));
30583062
}
30593063

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-
}
3064+
private AnnotatedMember invokeMethod(final BeanDescription beanDesc, String methodName) throws NoSuchMethodException, IllegalAccessException, InvocationTargetException{
3065+
Method m = BeanDescription.class.getMethod(methodName);
3066+
return (AnnotatedMember) m.invoke(beanDesc);
30673067
}
30683068

30693069
protected Schema buildRefSchemaIfObject(Schema schema, ModelConverterContext context) {

0 commit comments

Comments
 (0)