[Solved] No converter found for return value of type: class org.json.JSONObject

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: