No converter found for return value of type: class org json. Jsonobject
run error:
Servlet.service() for servlet [dispatcherServlet] in context with path [] threw exception [Request processing failed; nested exception is java.lang.NullPointerException] with root cause java.lang.NullPointerException: ····································
I can’t see any specific mistakes here
Go to the front page F12 and see the display: no converter found for return value of type: class.org.json.jSONObject
Layer controller code:
// Update the Users' information @ResponseBody @RequestMapping(value = "/user/update", method = RequestMethod.POST) public Object updateUserMsg(HttpServletRequest req) { JSONObject jsonObject = new JSONObject(); String id = req.getParameter("id").trim(); String username = req.getParameter("username").trim(); String password = req.getParameter("password").trim(); String sex = req.getParameter("sex").trim(); String phone = req.getParameter("phone").trim(); String email = req.getParameter("email").trim(); String birth = req.getParameter("birth").trim(); String introduction = req.getParameter("introduction").trim(); String location = req.getParameter("location").trim(); // String avatar = req.getParameter("avatar").trim(); // System.out.println(username + " " + password + " " + sex + " " + phone + " " + email + " " + birth + " " + introduction + " " + location); if (username.equals("") || username == null) { jsonObject.put("code", 0); jsonObject.put("msg", "The Username or Password is Wrong"); return jsonObject; } Consumer consumer = new Consumer(); DateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd"); Date myBirth = new Date(); try { myBirth = dateFormat.parse(birth); } catch (Exception e) { e.printStackTrace(); } consumer.setId(Integer.parseInt(id)); consumer.setUsername(username); consumer.setPassword(password); consumer.setSex(new Byte(sex)); consumer.setPhone(phone); consumer.setEmail(email); consumer.setBirth(myBirth); consumer.setIntroduction(introduction); consumer.setLocation(location); // consumer.setAvatar(avatar); consumer.setUpdateTime(new Date()); boolean res = consumerService.updateUserMsg(consumer); if (res) { jsonObject.put("code", 1); jsonObject.put("msg", "Modified Successfully"); return jsonObject; } else { jsonObject.put("code", 0); jsonObject.put("msg", "Failed to Modified"); return jsonObject; } }
Reason for error reporting:
java original org.json.jsonobject cannot return JSON data as a return value
solution:
requires
Introduce in POM:
<dependency> <groupId>com.alibaba</groupId> <artifactId>fastjson</artifactId> <version>1.2.47</version> </dependency>
Similar Posts:
- [Solved] net.sf.json.JSONException: java.lang.ClassCastException: JSON keys must be strings.
- [Solved] Cannot call sendRedirect() after the response has been committed
- [Solved] Error resolving template “XXX”, template might not exist or might not be accessible by any of the
- [Solved] java.lang.IllegalArgumentException: Cannot format given Object as a Date
- Example of Django model unique together
- TypeError: Object of type ‘datetime‘ is not JSON serializable [Solved]
- Golang Read 163 & 126 Mail Error: select inbox err: SELECT Unsafe Login. Please contact [email protected] for help
- [Solved] Exception in thread “main” javax.net.ssl.SSLHandshakeException: Received fatal alert: handshake_failure
- Get the time value from the database and report an error: Java sql. Timestamp cannot be cast to java. lang.Long
- [Solved] Python Error: datetime.datetime is not JSON serializable