swagger-api / swagger-core

Examples and server integrations for generating the Swagger API Specification, which enables easy access to your REST API
http://swagger.io
Apache License 2.0
7.37k stars 2.17k forks source link

Swagger overriding Jackson ObjectMapper (jacksonJaxbjsonprovider) #3278

Open kennywk opened 5 years ago

kennywk commented 5 years ago

Hello,

Currently running Swagger 1.5.20 with Jersey 2.29 and Spring, and i'm experiencing some strange JSON serialization behavior. Everything is wired up correctly (so i thought) and the UI will display the API listing; however, when serializing the response i get the following:

{ status: "success", data: "User(id=i,name=me,etc,etc)" }

It appears that the ObjectMapper being registered with Jersey is attempting to call toString when serializing the data property of the response object. The type of data is Object.class and i've even attempted to write a custom serializer. To test i manually serialize the response with my custom object mapper to a string and place that in the JaxRS Response object. The output is as expected so i'm assuming that Swagger's provider is overriding the one used within the jersey container. To validate this theory i use the Json.mapper().pretty method with the same object and i get the response that is causing the issue.

Any thoughts or ideas as to how i can separate the Swagger provider from the rest of the environment? This issue has been brought up before it seems.

Perhaps i'm missing something?

kennywk commented 5 years ago

So after further investigation if i write a explicit MessageBodyWriter, it will write, otherwise it attempts to serialize using the default as previously mentioned.