Skip to content

Commit

Permalink
Update findJsonValueType method to provide better support for Jackson…
Browse files Browse the repository at this point in the history
… < 2.9
  • Loading branch information
micryc committed Oct 9, 2024
1 parent a36f8b5 commit 03fcbcc
Showing 1 changed file with 20 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -1116,18 +1116,18 @@ 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
try {
Method m = BeanDescription.class.getMethod("findJsonValueAccessor");
AnnotatedMember jsonValueMember = (AnnotatedMember)m.invoke(beanDesc);
if (jsonValueMember != null) {
return jsonValueMember.getType();
}
} catch (NoSuchMethodException | IllegalAccessException | InvocationTargetException e) {
AnnotatedMember jsonValueMember = invokeMethod(beanDesc, "findJsonValueAccessor");
if (jsonValueMember != null) {
return jsonValueMember.getType();
} else {
LOGGER.warn("jackson BeanDescription.findJsonValueAccessor not found, this could lead to inaccurate result, please update jackson to 2.9+");
final AnnotatedMethod jsonValueMethod = beanDesc.findJsonValueMethod();
if (jsonValueMethod != null) {
return jsonValueMethod.getType();
}
}

jsonValueMember = invokeMethod(beanDesc, "findJsonValueMethod");
if (jsonValueMember != null) {
return jsonValueMember.getType();
} else {
LOGGER.error("Neither 'findJsonValueMethod' nor 'findJsonValueAccessor' found in jackson BeanDescription. Please verify your Jackson version.");
}
return null;
}
Expand Down Expand Up @@ -3057,6 +3057,15 @@ 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;
}
}

protected Schema buildRefSchemaIfObject(Schema schema, ModelConverterContext context) {
if (schema == null) {
return null;
Expand Down

0 comments on commit 03fcbcc

Please sign in to comment.