Spring MVC Converter when to perform conversions

Source: Internet
Author: User

the parameters that are normally passed from the foreground to the backend need to be converted, such as the date type, the Jsonobject type, the Jsonarray type, and so on. But when did spring change this step?

Java.text.parseexception:a Jsonobject must begin with ' {' at character 1 of [email protected] at Org.json.JSONTo Kener.syntaxerror (jsontokener.java:374) at org.json.jsonobject.<init> (jsonobject.java:127) at Org.json.JSONO Bject.<init> (jsonobject.java:166) at Com.trinitesolutions.core.web.convert.JSONObjectConverter.convert ( JSONOBJECTCONVERTER.JAVA:25) at Com.trinitesolutions.core.web.convert.JSONObjectConverter.convert ( jsonobjectconverter.java:1) at org.springframework.core.convert.support.genericconversionservice$ Converteradapter.convert (genericconversionservice.java:517) at Org.springframework.core.convert.support.ConversionUtils.invokeConverter (conversionutils.java:35) at Org.springframework.core.convert.support.GenericConversionService.convert (genericconversionservice.java:171) at Org.springframework.beans.TypeConverterDelegate.convertIfNecessary (typeconverterdelegate.java:143) at Org.springframework.beans.TypeConverterDelegate.convErtifnecessary (typeconverterdelegate.java:92) at Org.springframework.beans.SimpleTypeConverter.convertIfNecessary (simpletypeconverter.java:49) at Org.springframework.validation.DataBinder.convertIfNecessary (databinder.java:553) at Org.springframework.web.method.annotation.AbstractNamedValueMethodArgumentResolver.resolveArgument ( ABSTRACTNAMEDVALUEMETHODARGUMENTRESOLVER.JAVA:97) at Org.springframework.web.method.support.HandlerMethodArgumentResolverComposite.resolveArgument ( HANDLERMETHODARGUMENTRESOLVERCOMPOSITE.JAVA:75) at Org.springframework.web.method.support.InvocableHandlerMethod.getMethodArgumentValues ( invocablehandlermethod.java:156) at Org.springframework.web.method.support.InvocableHandlerMethod.invokeForRequest (invocablehandlermethod.java:117 ) at Org.springframework.web.servlet.mvc.method.annotation.ServletInvocableHandlerMethod.invokeAndHandle ( servletinvocablehandlermethod.java:96) at Org.springframework.web.servlet.mvc.method.annotation.RequestMappingHAndleradapter.invokehandlermethod (requestmappinghandleradapter.java:617) at Org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter.handleInternal ( requestmappinghandleradapter.java:578) at Org.springframework.web.servlet.mvc.method.AbstractHandlerMethodAdapter.handle ( ABSTRACTHANDLERMETHODADAPTER.JAVA:80) at Org.springframework.web.servlet.DispatcherServlet.doDispatch ( dispatcherservlet.java:923) at Org.springframework.web.servlet.DispatcherServlet.doService ( dispatcherservlet.java:852) at Org.springframework.web.servlet.FrameworkServlet.processRequest (    frameworkservlet.java:882) at Org.springframework.web.servlet.FrameworkServlet.doPost (frameworkservlet.java:789) At Javax.servlet.http.HttpServlet.service (httpservlet.java:647) at Javax.servlet.http.HttpServlet.service ( httpservlet.java:728) at Org.apache.catalina.core.ApplicationFilterChain.internalDoFilter ( applicationfilterchain.java:305) at Org.apache.catalina.core.ApplicationFiltErchain.dofilter (applicationfilterchain.java:210) at Org.apache.tomcat.websocket.server.WsFilter.doFilter ( wsfilter.java:51) at Org.apache.catalina.core.ApplicationFilterChain.internalDoFilter ( applicationfilterchain.java:243) at Org.apache.catalina.core.ApplicationFilterChain.doFilter ( applicationfilterchain.java:210) at Org.apache.shiro.web.servlet.ProxiedFilterChain.doFilter ( proxiedfilterchain.java:61) at Org.apache.shiro.web.servlet.AdviceFilter.executeChain (advicefilter.java:108) at Org.apache.shiro.web.servlet.AdviceFilter.doFilterInternal (advicefilter.java:137) at Org.apache.shiro.web.servlet.OncePerRequestFilter.doFilter (onceperrequestfilter.java:125) at Org.apache.shiro.web.servlet.ProxiedFilterChain.doFilter (proxiedfilterchain.java:66) at Org.apache.shiro.web.servlet.AbstractShiroFilter.executeChain (abstractshirofilter.java:449) at Org.apache.shiro.web.servlet.abstractshirofilter$1.call (abstractshirofilter.java:365) at Org.apache.shiro.subject.suPport. Subjectcallable.docall (subjectcallable.java:90) at Org.apache.shiro.subject.support.SubjectCallable.call ( subjectcallable.java:83) at Org.apache.shiro.subject.support.DelegatingSubject.execute (Delegatingsubject.java : 383) at Org.apache.shiro.web.servlet.AbstractShiroFilter.doFilterInternal (abstractshirofilter.java:362) at Org.apache.shiro.web.servlet.OncePerRequestFilter.doFilter (onceperrequestfilter.java:125) at Org.springframework.web.filter.DelegatingFilterProxy.invokeDelegate (delegatingfilterproxy.java:346) at Org.springframework.web.filter.DelegatingFilterProxy.doFilter (delegatingfilterproxy.java:259) at Org.apache.catalina.core.ApplicationFilterChain.internalDoFilter (applicationfilterchain.java:243) at Org.apache.catalina.core.ApplicationFilterChain.doFilter (applicationfilterchain.java:210) at Org.springframework.orm.jpa.support.OpenEntityManagerInViewFilter.doFilterInternal ( openentitymanagerinviewfilter.java:147) at Org.springframework.web.filteR.onceperrequestfilter.dofilter (onceperrequestfilter.java:76) at Org.apache.catalina.core.ApplicationFilterChain.internalDoFilter (applicationfilterchain.java:243) at Org.apache.catalina.core.ApplicationFilterChain.doFilter (applicationfilterchain.java:210) at Org.springframework.web.filter.CharacterEncodingFilter.doFilterInternal (characterencodingfilter.java:88) at Org.springframework.web.filter.OncePerRequestFilter.doFilter (onceperrequestfilter.java:76) at Org.apache.catalina.core.ApplicationFilterChain.internalDoFilter (applicationfilterchain.java:243) at Org.apache.catalina.core.ApplicationFilterChain.doFilter (applicationfilterchain.java:210) at Org.apache.catalina.core.StandardWrapperValve.invoke (standardwrappervalve.java:222) at Org.apache.catalina.core.StandardContextValve.invoke (standardcontextvalve.java:123) at Org.apache.catalina.authenticator.AuthenticatorBase.invoke (authenticatorbase.java:502) at Org.apache.catalina.core.StandardHostValve.invoke (Standardhostvalve.java:171) at Org.apache.catalina.valves.ErrorReportValve.invoke (errorreportvalve.java:100) at Org.apache.catalina.valves.AccessLogValve.invoke (accesslogvalve.java:953) at Org.apache.catalina.core.StandardEngineValve.invoke (standardenginevalve.java:118) at Org.apache.catalina.connector.CoyoteAdapter.service (coyoteadapter.java:408) at Org.apache.coyote.http11.AbstractHttp11Processor.process (abstracthttp11processor.java:1041) at Org.apache.coyote.abstractprotocol$abstractconnectionhandler.process (abstractprotocol.java:603) at Org.apache.tomcat.util.net.jioendpoint$socketprocessor.run (jioendpoint.java:312) at Java.util.concurrent.ThreadPoolExecutor.runWorker (threadpoolexecutor.java:1110) at Java.util.concurrent.threadpoolexecutor$worker.run (threadpoolexecutor.java:603) at Java.lang.Thread.run ( thread.java:722)

each time the foreground sends a request, the backend will have the appropriate controller to execute the request. Spring calls the controller through the HTTP request method is the same as the reflection of the way, through the handermapping to find the corresponding controller and method, and then to do is based on the parameter type, The parameter name is passed to the method from the request or modelandviewcontainer,webdatabinderfactory to find the corresponding parameter. When this parameter is found, spring determines whether to convert the parameter according to the type of the parameter, and then finds the corresponding registered converter to perform the conversion.

It is also easy to see through the conversion of abnormal information, and spring is really a conversion when looking for a method parameter. The time to do the conversion is actually the most appropriate moment. Because if the conversion is done before the Controller method is called, it is possible that those parameters that are not used in this request are converted, so that the execution efficiency is reduced.



Spring MVC Converter when to perform conversions

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.