Closed seawatts closed 10 years ago
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.
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:
and it didnt seem to work
@faddy can you create a pull request so we can integrate this fix into the main branch.
Thanks
@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.
Thanks that did fix the issue. Now I am having another problem. Issue #32
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!
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"
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.
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?
@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 will.kennedy@sparcedge.com
Thanks!
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.
I just tried this out with no luck.
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.
andrew@creativeclaritycreations.com | 404.372.7430 | @clearcreativity
On Jan 17, 2014, at 4:46 PM, Will Kennedy notifications@github.com 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.
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.... ;)
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?