Skip to content

Commit

Permalink
fix findJsonValueType
Browse files Browse the repository at this point in the history
  • Loading branch information
frantuma committed Oct 24, 2024
1 parent affcb1d commit 7a3c353
Showing 1 changed file with 15 additions and 15 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -1116,17 +1116,21 @@ protected Type findJsonValueType(final BeanDescription beanDesc) {

// use recursion to check for method findJsonValueAccessor existence (Jackson 2.9+)
// if not found use previous deprecated method which could lead to inaccurate result
AnnotatedMember jsonValueMember = invokeMethod(beanDesc, "findJsonValueAccessor");
if (jsonValueMember != null) {
return jsonValueMember.getType();
} else {
try {
AnnotatedMember jsonValueMember = invokeMethod(beanDesc, "findJsonValueAccessor");
if (jsonValueMember != null) {
return jsonValueMember.getType();
}
} catch (Exception e) {
LOGGER.warn("jackson BeanDescription.findJsonValueAccessor not found, this could lead to inaccurate result, please update jackson to 2.9+");
}

jsonValueMember = invokeMethod(beanDesc, "findJsonValueMethod");
if (jsonValueMember != null) {
return jsonValueMember.getType();
} else {
try {
AnnotatedMember jsonValueMember = invokeMethod(beanDesc, "findJsonValueMethod");
if (jsonValueMember != null) {
return jsonValueMember.getType();
}
} catch (Exception e) {
LOGGER.error("Neither 'findJsonValueMethod' nor 'findJsonValueAccessor' found in jackson BeanDescription. Please verify your Jackson version.");
}
return null;
Expand Down Expand Up @@ -3057,13 +3061,9 @@ protected boolean isNumberSchema(Schema schema){
return "number".equals(schema.getType()) || (schema.getTypes() != null && schema.getTypes().contains("number")) || "integer".equals(schema.getType()) || (schema.getTypes() != null && schema.getTypes().contains("integer"));
}

private AnnotatedMember invokeMethod(final BeanDescription beanDesc, String methodName) {
try {
Method m = BeanDescription.class.getMethod(methodName);
return (AnnotatedMember) m.invoke(beanDesc);
} catch (NoSuchMethodException | IllegalAccessException | InvocationTargetException e) {
return null;
}
private AnnotatedMember invokeMethod(final BeanDescription beanDesc, String methodName) throws NoSuchMethodException, IllegalAccessException, InvocationTargetException{
Method m = BeanDescription.class.getMethod(methodName);
return (AnnotatedMember) m.invoke(beanDesc);
}

protected Schema buildRefSchemaIfObject(Schema schema, ModelConverterContext context) {
Expand Down

0 comments on commit 7a3c353

Please sign in to comment.