The advantage of using simplefilterprovider,propertyfilter is decoupling and flexibility. But the drawbacks are obvious.
Let's take a look at the way @jsonview is handled.
There is a configuration method in Webmvcconfigurationsupport, if the program has com.fasterxml.jackson.databind.ObjectMapper && The reference to the Com.fasterxml.jackson.core.JsonGenerator package will implement the Requestbodyadvice Jsonviewrequestbodyadvice and
Implemented the Responsebodyadvice Jsonviewresponsebodyadvice add in
@Bean PublicRequestmappinghandleradapter Requestmappinghandleradapter () {Requestmappinghandleradapter adapter=Createrequestmappinghandleradapter (); Adapter.setcontentnegotiationmanager (Mvccontentnegotiationmanager ()); Adapter.setmessageconverters (Getmessageconverters ()); Adapter.setwebbindinginitializer (Getconfigurablewebbindinginitializer ()); Adapter.setcustomargumentresolvers (Getargumentresolvers ()); Adapter.setcustomreturnvaluehandlers (Getreturnvaluehandlers ()); if(jackson2present) { adapter.setrequestbodyadvice (collections.singletonlist ( new Jsonviewrequestbodyadvice ())); Adapter.setresponsebodyadvice (Collections.singletonlist (New Jsonviewresponsebodyadvice ())); } asyncsupportconfigurer Configurer=NewAsyncsupportconfigurer (); Configureasyncsupport (Configurer); if(Configurer.gettaskexecutor ()! =NULL) {Adapter.settaskexecutor (Configurer.gettaskexecutor ()); } if(Configurer.gettimeout ()! =NULL) {adapter.setasyncrequesttimeout (Configurer.gettimeout ()); } adapter.setcallableinterceptors (Configurer.getcallableinterceptors ()); Adapter.setdeferredresultinterceptors (Configurer.getdeferredresultinterceptors ()); returnadapter; }
The final deal is that requestresponsebodyadvicechain this chain of responsibility
Using the Simplefilterprovider,propertyfilter custom control JSON return value, you will get the request directly, forcing the modification of the request header to JSON, and output, the end of the requests. The chain of responsibility was interrupted, So in the @restcontroller, it will fail.
Using @jsonview to compare with spring's design pattern, but the coupling is very strong, and you will find that if you want to return to the JPA page @JsonView is useless
Also to the page to do the following packaging
/** * @authorLaizhenwei * @date 2018/06/09*/@JsonView (View.class) Public classPagevo<t>extendsPageimpl<t>ImplementsPage<t> { Private Static Final LongSerialversionuid = -3530103094806749298l; PublicPagevo (FinalList<t> content,FinalPageable pageable,Final LongTotal ) { Super(content, pageable, total); } PublicPagevo (FinalList<t>content) { Super(content); } PublicPagevo (FinalPage<t> page,Finalpageable pageable) { Super(Page.getcontent (), pageable, page.gettotalelements ()); }
So still write Vo conversion, anyway to waste meta-space
Spring MVC precisely controls the return field Simplefilterprovider, @JasonView, and the selection of the VO view model