Swagger is it possible to override custom object s

2019-07-27 12:49发布

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条回答
Luminary・发光体
2楼-- · 2019-07-27 13:23

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

查看更多
登录 后发表回答