Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ApiDocumentationController - getResources() doesnt convert to JSON #33

Closed
seawatts opened this issue Jan 9, 2014 · 14 comments
Closed
Assignees

Comments

@seawatts
Copy link

seawatts commented Jan 9, 2014

I have just upgraded swagger to the following versions
swagger-core -> 1.3.1
swagger-annotations -> 1.3.0
swagger-ui -> 2.0.3
swagger4spring-web -> 0.3.0

After doing so I tried to go to /api/docs/resourceList and it returns "{ }"
When I step through your code in ApiDocumentationController - getResources() it looks like it creates the correct ResourceListing object however it looks like Spring/Jackson does not correctly convert it to a JSON object before it gets past back to the client.

I am using
Spring - 3.2.4.RELEASE
Jackson - 2.2.2

I have already tried to exclude jackson from getting imported from swagger-core

Any ideas on what could be happening here?

@faddy
Copy link

faddy commented Jan 9, 2014

Hi Eibach,

I faced the same issue and you're absolutely correct about the ResourceListing object not getting serialized. I got around the problem by hacking up the code to serialize the object using custom jackson serializer. By custom serializer, I mean simply adding the scala module: https://github.com/FasterXML/jackson-module-scala

This is still a hacky way of doing it, and I am a newb when it comes to Spring and Scala. :) It would be nice to know the 'right' way of doing this.

@seawatts
Copy link
Author

seawatts commented Jan 9, 2014

Hi @faddy,

I did see that module as well, but I refrained from using it because it looks like it is already being included when you import swagger-core.

I just tried using:

com.fasterxml.jackson.module jackson-module-scala_2.10 2.3.0

and it didnt seem to work

@seawatts
Copy link
Author

@faddy can you create a pull request so we can integrate this fix into the main branch.

Thanks

@faddy
Copy link

faddy commented Jan 12, 2014

@eibach The hack I used was to quickly get around the serialization issue for my specific use case. I am not sure how to actually fix the problem. IMO, a good way would be to use a custom JSON serializer in Spring itself, hence automatically serializing the scala objects into json objects. As I said, I am a noob at Spring, so not sure how to do that. :)

If you're interested, here is my APIDocumentationController: http://pastebin.com/UiAVn9kJ
I modified the swagger-ui.js to get documentation from the url 'resourceListWrapper/doc' instead of 'resourceList/doc', which gets directed to these methods which use the modified serializer.

Again, this is just a hack and not an actual fix.

@seawatts
Copy link
Author

Thanks that did fix the issue. Now I am having another problem. Issue #32

@ghost ghost assigned wkennedy Jan 13, 2014
@wkennedy
Copy link
Owner

Thank you for finding this issue. Here is a way to get around this problem. Add the following to the appropriate Spring context file for your application:

<annotation-driven>
    <message-converters>
        <beans:bean class="org.springframework.http.converter.json.MappingJackson2HttpMessageConverter">
            <beans:property name="objectMapper">
                <beans:bean class="com.knappsack.swagger4springweb.util.ScalaObjectMapper"/>
            </beans:property>
        </beans:bean>
    </message-converters>
</annotation-driven>

Please let me know if you are still seeing issues.

Thanks!

@seawatts
Copy link
Author

When I insert that into my applicationContext.xml it gives me an error "Element beans:bean does not belong here"
I also had to prepend "mvc:" to message-converters and I already had "mvc:annotation-driven"

@andrewrutter
Copy link

Moving some of the comments over from #34: I have tried the approaches above with no joy. Regardless of version 0.2.0 or 0.3.0 the library does not seem to be building the list of API endpoints at all.

@seawatts
Copy link
Author

After I implemented @faddy 's solution I am now seeing
"base url: https://localhost/api/docs/resourceListWrapper"

at the bottom of the swagger ui, and before it was showing the correct base "https://localhost/api/v1"

Any ideas?

@wkennedy
Copy link
Owner

@eibach and @andrewrutter
Can I get examples of your Spring context files and pom files and possibly your controller if you are extending ApiDocumentationController. The only way I have been able to reproduce this so far is by removing

 <beans:bean class="com.knappsack.swagger4springweb.util.ScalaObjectMapper"/>

from the Jackson message converters.

If you don't want to post them you can email me at [email protected]

Thanks!

@wkennedy
Copy link
Owner

So, it looks like this is most likely an issue if you have a dependency or transitive dependency on jackson-databind with a version greater than 2.1.5. If this is the case try adding the following dependency on jackson-module-scala_2.10 and excluding the one in swagger4spring-web. For example:

    <dependency>
        <groupId>com.fasterxml.jackson.module</groupId>
        <artifactId>jackson-module-scala_2.10</artifactId>
        <version>2.3.0</version>
    </dependency>

    <dependency>
        <groupId>com.knappsack</groupId>
        <artifactId>swagger4spring-web</artifactId>
        <version>0.3.0</version>
        <exclusions>
            <exclusion>
                <artifactId>jackson-module-scala_2.10</artifactId>
                <groupId>com.fasterxml.jackson.module</groupId>
            </exclusion>
        </exclusions>
    </dependency>

I'll create an issue on Swagger's GitHub site to update jackson-module-scala_2.10 to at least 2.3. I'll also update the swagger4spring-web pom to exclude the older version of jackson-module-scala_2.10 and include the newer one.

@seawatts
Copy link
Author

I just tried this out with no luck.

wkennedy pushed a commit that referenced this issue Jan 21, 2014
…est jackson-module-scala_2.10 dependency. See: #33
@andrewrutter
Copy link

Other than dependency problems which is just the usual Maven fun and games, I have finally tracked the issue here down to the version of Reflections in use. Looks like there is a known problem with that lib on WebSphere:

https://code.google.com/p/reflections/issues/detail?id=124

I think it is fixed in the current version but that is RC only and also breaks the build of swagger4spring due to some api changes!

Back to the drawing board here I think unless there is a way to up the reflections version? I see a couple of proposed workarounds so will carry on looking.

Thanks for digging into it, at least I know what my issue is now!!

Andrew Rutter
President
Creative Clarity Inc.

[email protected] | 404.372.7430 | @ClearCreativity

On Jan 17, 2014, at 4:46 PM, Will Kennedy [email protected] wrote:

So, it looks like this is most likely an issue if you have a dependency or transitive dependency on jackson-databind with a version greater than 2.1.5. If this is the case try adding the following dependency on jackson-module-scala_2.10 and excluding the one in swagger4spring-web. For example:

<dependency>
    <groupId>com.fasterxml.jackson.module</groupId>
    <artifactId>jackson-module-scala_2.10</artifactId>
    <version>2.3.0</version>
</dependency>

<dependency>
    <groupId>com.knappsack</groupId>
    <artifactId>swagger4spring-web</artifactId>
    <version>0.3.0</version>
    <exclusions>
        <exclusion>
            <artifactId>jackson-module-scala_2.10</artifactId>
            <groupId>com.fasterxml.jackson.module</groupId>
        </exclusion>
    </exclusions>
</dependency>

I'll create an issue on Swagger's GitHub site to update jackson-module-scala_2.10 to at least 2.3. I'll also update the swagger4spring-web pom to exclude the older version of jackson-module-scala_2.10 and include the newer one.


Reply to this email directly or view it on GitHub.

@nithril
Copy link

nithril commented Mar 4, 2014

I got the same issue.
Spring: 4.0.1
swagger-core: 1.3.2
swagger4spring-web: 0.3.0

I made the mistake of appending the message converter at the end of the converters list

At the beginning I get the correct result.... ;)

@wkennedy wkennedy closed this as completed Mar 7, 2014
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

5 participants