Swagger is it possible to override custom object serialization

谁说胖子不能爱 提交于 2019-12-11 04:39:59

问题


I have been testing swagger in order to use it as the defacto documentation for my api service. I am using hibernate for the persistence layer and every response is bound to an entity. The problem is that those entities have dependencies with other entities and I would like to orchestrate swagger to not show those entities when I pass the object in the @ApiOperation response. The only think I could find on line is this link from the github page.

I have tried doing this:

String emptyJSON = "{}";
OverrideConverter addressConverter = new OverrideConverter();
addressConverter.add(User.class.getCanonicalName(), emptyJSON);
ModelConverters.addConverter(addressConverter, true);

but I am getting this error:

org.json4s.package$MappingException: Did not find value which can be converted into java.lang.String

Is there a way to avoid serializing some classes when I find them as fields or in lists and how?


回答1:


Ok so it appears that you can use

 OverrideConverter sessionConverter = new OverrideConverter();
 sessionConverter.add(Session.class.getName(), emptyJSON);
 ModelConverters.addConverter(sessionConverter, true);

For globally avoiding serialization. Also if you need to avoid inner objects from serializing then just change all the getter methods to something else, seems like swagger is using this the getters and not reflections which sucks in my opinion. Hope that helps



来源:https://stackoverflow.com/questions/18677498/swagger-is-it-possible-to-override-custom-object-serialization

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!