swagger-core icon indicating copy to clipboard operation
swagger-core copied to clipboard

Swagger Core is not compatible with Jackson 2.18.x

Open jamesnetherton opened this issue 2 years ago • 3 comments

ModelResolver.findJsonVauleType references Jackson BeanDescription.findJsonVauleMethod which was deprecated since Jackson 2.9. It got removed in Jackson 2.18.0, hence there's the potential for runtime errors if Jackson 2.18.x is on the classpath. Or build time errors if GraalVM is used to create a native application.

jamesnetherton avatar Oct 04 '24 07:10 jamesnetherton

Hi @jamesnetherton thank you for reporting, possible problem should be solved by: https://github.com/swagger-api/swagger-core/pull/4756, Closing ticket for now, If you will experience any problem, feel free to reopen

micryc avatar Oct 09 '24 14:10 micryc

Hi, unfortunately the change in #4756 introduces new problems when using Jackson 2.18 (in my case: Jackson 2.18.1). Now my log gets flooded with messages like:

2024-11-21 15:26:41,430	ERROR	io.swagger.v3.core.jackson.ModelResolver	Neither 'findJsonValueMethod' nor 'findJsonValueAccessor' found in jackson BeanDescription. Please verify your Jackson version.
2024-11-21 15:26:41,434	ERROR	io.swagger.v3.core.jackson.ModelResolver	Neither 'findJsonValueMethod' nor 'findJsonValueAccessor' found in jackson BeanDescription. Please verify your Jackson version.
...

After a bit of debugging, I found the reason: In this Jackson version the method BeanDescription.findJsonValueAccessor() does exist, but BeanDescription.findJsonValueMethod() has been removed. However, due to the code structure, the first call to invokeMethod(beanDesc, "findJsonValueAccessor") does not throw an exception, but returns null in my case. Therefore the function findJsonValueType does not return in the first try-Block, and still tries to execute the old/deprecated/removed method invokeMethod(beanDesc, "findJsonValueMethod"), which does print out the error.

I think this problem would be fixed, if the first executed method would just return a value anyways, if no exception during the method execution occurred.

E.g.

try {
    AnnotatedMember jsonValueMember = invokeMethod(beanDesc, "findJsonValueAccessor");
    if (jsonValueMember != null) {
        return jsonValueMember.getType();
    }
    return null;
} catch (Exception e) {
    LOGGER.warn("jackson BeanDescription.findJsonValueAccessor not found, this could lead to inaccurate result, please update jackson to 2.9+");
}

edit: I've encountered this problem with Swagger-Core 2.2.26, but also looked in the current master branch, and saw that the relevant code fragment is the same, as the one I've debugged with

metaxmx avatar Nov 21 '24 14:11 metaxmx

fixed in #4806 4806

frantuma avatar Dec 11 '24 14:12 frantuma