问题描述
我一直在测试swagger,以便将它用作我的api服务的事实文档。
我正在使用hibernate作为持久层,每个响应都绑定到一个实体。
问题是这些实体与其他实体有依赖关系,当我在@ApiOperation响应中传递对象时,我想协调swagger以不显示这些实体。
我能在网上找到的唯一想法是 page。
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.
我试过这样做:
String emptyJSON = "{}";
OverrideConverter addressConverter = new OverrideConverter();
addressConverter.add(User.class.getCanonicalName(), emptyJSON);
ModelConverters.addConverter(addressConverter, true);
但我收到此错误:
当我将它们作为字段或列表发现时,有没有办法避免序列化某些类?如何?
Is there a way to avoid serializing some classes when I find them as fields or in lists and how?
推荐答案
确定所以看起来你可以使用
Ok so it appears that you can use
OverrideConverter sessionConverter = new OverrideConverter();
sessionConverter.add(Session.class.getName(), emptyJSON);
ModelConverters.addConverter(sessionConverter, true);
全局避免序列化。
另外如果你需要避免内部对象序列化,那么只需将所有的getter方法更改为其他东西,看起来swagger正在使用这个getter而不是我认为很糟糕的反射。
希望有帮助
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
这篇关于Swagger可以覆盖自定义对象序列化的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!