development environment :spring-mvc4.1.7、fastjson1.2.7

Problem description : The front and back ends of the system are completely separated , The front page uses ajax When calling a background service , Want to use fastjson Automatically convert request parameter object .

// Front end calls 
$.ajax({
url : "bas/test.do",
type : "POST",
async : true,
contentType : "application/json; charset=utf-8",
data : country,// Definition of outer layer json object
success : function(rst) {alert(JSON.stringify(rst));
}
// Background services 
1 @ResponseBody
@RequestMapping(value = "/add.do", method = { RequestMethod.POST, RequestMethod.GET }, produces = "application/json;charset=UTF-8")
public void add(@RequestBody Country country) {
// ...
}
 Run the error stack , as follows :
serious : Servlet.service() for servlet [SpringMVC] in context with path [/mfd] threw exception [Request processing failed; nested exception is com.alibaba.fastjson.JSONException: syntax error, expect {, actual error, pos 0] with root cause
com.alibaba.fastjson.JSONException: syntax error, expect {, actual error, pos 0
at com.alibaba.fastjson.parser.deserializer.JavaBeanDeserializer.deserialze(JavaBeanDeserializer.java:232)

Online search for various solutions failed , Finally, try to json Object to json character string , Successful call .

It is amended as follows data : JSON.stringify(country)

The last project used jackson when ,data The parameters are transferred directly to json object ,fastjson Not in favor of this way ...

fastjson Automatic conversion parameter error more related articles

  1. Unit testing uses [ClassInitialize] The method must be static and public , Does not return a value and should take a TestContext Type of parameter error solution

    using Microsoft.VisualStudio.TestTools.UnitTesting; If it's time to DLL The application is C:\Program Files\Microsoft Visual Stu ...

  2. 【spring mvc】 backstage spring mvc receive List The parameter error is as follows :org.springframework.beans.BeanInstantiationException: Failed to instantiate [java.util.List]: Specified class is an interface

    backstage spring mvc receive List The parameter error is as follows :org.springframework.beans.BeanInstantiationException: Failed to instantiate ...

  3. CreateMutex() Parameter error

    give an example : hMutex = CreateMutex(NULL, FALSE,"screen"); Report errors  error C2664:"CreateMutexW": No ...

  4. About tomcat Incorrect coding url Solution of parameter error report

    According to the code ,url Parameters must use qualified characters , Other characters need to be encoded , Use as js Of encodeurlcomponent function . stay IE and 360 Browser compatibility mode , Not automatically url The parameters are encoded , It can lead to tomcat Report errors ...

  5. ibatis A solution to the problem of error reporting by taking the table name as a parameter

    use ibatis When , I want to pass in the table name as a parameter , But the report is wrong , stay ibatis In the configuration file is #resource# The way , The error information is as follows : org.apache.cxf.interceptor.Fault ...

  6. ORA-16019 build DG Set the archive thread parameters to report an error

    # Operation description : build DG, Modify parameters of main database log_archive_dest_1 Thread path error ORA-16019: cannot use LOG_ARCHIVE_DEST_1 with LOG_ARCHIVE_ ...

  7. mybatis Chinese parameter error report

    A simple query , If there is Chinese in the parameter . as follows : <select id="xxxx" resultType="hashmap"> select * from ...

  8. HP-UNIX Platform modification Oracle processes Parameter error :ORA-27154、ORA-27300、ORA-27301、ORA-27302

    OS edition      :HP-UX B.11.31Oracle edition :11.2.0.4 (RAC) ( One ) Problem description Recently we found that we can't connect to the database , The error message is “ORA-00020:maximum number ...

  9. MyBatis Multiple interface parameters error :Available parameters are [0, 1, param1, param2], And solutions

    1. sql The statement is as follows : SELECT * FROM tb_crm_user WHERE id = #{userId, jdbcType=INTEGER} AND user_name = #{userN ...

Random recommendation

  1. Python str Methods to summarize

    1. Returns the first capital letter S.capitalize(...) S.capitalize() -> string 1 2 3 4 >>>a = 'shaw' >>> ...

  2. HBase One of the studies &lt;&lt;HBase Using client API Dynamically create Hbase Data table and in Hbase Next export execution &gt;&gt;

    HBase Using client API Dynamically create Hbase Data table and in Hbase Next export execution                       ---- First of all, thank the Internet for providing me with an open learning platform , If there is no online technology enthusiast to provide ...

  3. hdu2368Alfredo&#39;s Pizza Restaurant

    Problem Description Traditionally after the Local Contest, judges and contestants go to their favour ...

  4. Leetcode Answer key (31)

    103. Binary Tree Zigzag Level Order Traversal subject analysis : The application of breadth first traversal . The point is to master vector Of reverse function , I forgot to have this function at first , Ponder over ...

  5. element-ui and npm、webpack、vue-cli build Vue project

    One .element-ui Simple use 1. install 1. npm install Recommended npm Mode of installation , It can be better with webpack Packing tools are used with . npm i element-ui -S 2. CDN ...

  6. qr-mili Tekniskt st&#246;d

    qr-mili Är ett QR-kodverktyg Identifiera enkelt QR-koder Generera QR-kod Skapa en QR-kod med logotyp ...

  7. Codeforces 996E Leaving the Bar ( randomization )

    Topic linking :Leaving the Bar The question : Here you are. n Vector , You can add this vector or subtract this vector , So that the length of the sum of these vectors is less than 1.5e6. Answer key :  In the normal greedy way , The final result may be greater than 1.5e6 . Here I am ...

  8. day32- Common built-in module 1 (random、time、datetime、os、sys)

    One .random modular # Random decimal >>> random.random() # Greater than 0 And less than 1 Decimal between 0.7664338663654585>>> random.uni ...

  9. Alpha Sprint report (2/12)( Muggle makers )

    Today's task summary The burn out diagram is as follows : The details are as follows : Jiang Zheng : today : Completed the basic construction of commodity demand database . Problems encountered : about php Of ci The frame is not familiar , I don't understand the operation principle Tomorrow, : Docking database with teammates Fu Tianyu : today : complete ...

  10. 【CC2530 Strengthen practical training 03】 Timer interval timing to achieve key long press and short press

    [CC2530 Strengthen practical training 03] Timer interval timing to achieve key long press and short press [ Subject requirements ] Although the ordinary delay function can realize the discrimination between long press and short press of key , But it is not easy to use and flexible in practical engineering application and project development . More with the interval of the timer ...