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

Exception with Api method returning custom model

Open m-radzikowski opened this issue 11 years ago • 8 comments

I'm stuck with simple, small Swagger app. With dependency on swagger-jersey2-jaxrs in version 1.5.0-M2 (also tested 1.5.0-M1, 1.5.1-M1, 1.5.1-M2, 1.5.3-M1) when deploying project to Glassfish 4.1 I'm getting

Severe:   Exception while invoking class com.sun.enterprise.web.WebApplication start method
java.lang.Exception: java.lang.IllegalStateException: ContainerBase.addChild: start: org.apache.catalina.LifecycleException: org.apache.catalina.LifecycleException: java.lang.NoSuchMethodError: com.fasterxml.jackson.databind.AnnotationIntrospector.findPropertyIndex(Lcom/fasterxml/jackson/databind/introspect/Annotated;)Ljava/lang/Integer;

My classes:

@ApplicationPath("/rest")
public class RestApplication extends Application {
    public RestApplication() {
        BeanConfig beanConfig = new BeanConfig();
        beanConfig.setVersion("1.0.2");
        beanConfig.setSchemes(new String[]{"http"});
        beanConfig.setHost("localhost:8080");
        beanConfig.setBasePath("/SwaggerTest/api");
        beanConfig.setResourcePackage("com.example.swaggertest.facade");
        beanConfig.setScan(true);
    }

    @Override
    public Set<Class<?>> getClasses() {
        Set<Class<?>> resources = new HashSet<>();

        resources.add(TestFacade.class);

        resources.add(com.wordnik.swagger.jaxrs.listing.ApiListingResource.class);
        resources.add(com.wordnik.swagger.jaxrs.listing.SwaggerSerializers.class);

        return resources;
    }
}
@Path("/test")
@Api
public class TestFacade {
    @GET
    @ApiOperation(value = "lorem ipsum")
    public Mock test() {
        return new Mock();
    }
}
@XmlRootElement
public class Mock {
    private String s;

    public String getS() {
        return s;
    }

    public void setS(String s) {
        this.s = s;
    }
}

Everything is good when Mock class is empty, without any properties (s in this case).

Am I missing something?

m-radzikowski avatar Apr 22 '15 09:04 m-radzikowski

That's a problem with Glassfish 4.1 as it includes an old version of Jackson that supersedes the one provided with swagger-core.

To solve it, you'll have to:

  • Download Glassfish-4.1 b13
  • Replace all the Jackson jars under the common lib with version 2.42

webron avatar Apr 22 '15 14:04 webron

Ok, thank you for the response. It's sad that Glassfish does it.

It would be great if that info would appear in wiki.

Issue to close.

m-radzikowski avatar Apr 23 '15 07:04 m-radzikowski

Hello guys,

I'm having the same problem and I would like to solve this without change the jars inside the glassfish. Because if I do that in the production environment it's possible to happens anothers issuing with other applications.

There's another way to solve this?

Thank you.

santosdealmeidaelias avatar Sep 23 '15 13:09 santosdealmeidaelias

I'm afraid there's no way around it, as far as I know.

And yes, you should always test such changes in some testing environment before changing in production ;)

webron avatar Sep 23 '15 13:09 webron

It's not a good news, but thank you.

santosdealmeidaelias avatar Sep 23 '15 14:09 santosdealmeidaelias

Thanks! I had the same problem. Replacing the five jackson jars (annoations, core, databind, jaxrs-base, jaxrs-json-provider) in the /glassfish/modules folder with the version 2.8.5 solved the problem.

Kiolali avatar May 02 '17 09:05 Kiolali

@Kiolali could you paste your pom.xml?

shankar96 avatar Mar 12 '19 16:03 shankar96

I just annotated Path with @ApiModelProperty(hidden = true) it started working i am not sure its wrong or right?

shankar96 avatar Mar 12 '19 16:03 shankar96