java.lang.IllegalArgumentException:未找到类型为java.util.ArrayList的返回值的转换器

时间:2019-06-06 08:31:06

标签: java json spring

我正在使用此代码以JSON形式返回学生列表

class ClientThread(Thread): 

    def __init__(self,ip,port): 
        Thread.__init__(self) 
        self.ip = ip 
        self.port = port 

    def run(self): 

        while True :
            data = conn.recv(2048) 

            // it errors here stating index out of range. 
            // I can add checks, but would like to prevent/not detect this seccond request
            parsed_url = urlparse(data.split()[1].decode("utf-8"))

            dctParams = parse_qs(parsed_url.query)

            if "ProductID" in dctParams:
                sProductID = dctParams.get("ProductID")[0]
            else:
                print("Unable to find key. Continuing")
                break #continue

            print("Requested ProductID: ", sProductID, "found. Attempting to find matches")

            bSuccess = True

            try:
                aOut = data_matrix.loc[sProductID].nlargest(10)
                print("Request satisfied")
                print(aOut)
                print("\n\n")
            except:
                bSuccess = False
                print("Error Finding product in data set")

            byt = ""

            if bSuccess:
                byt = json.dumps({'Success': True, 'Data': aOut.to_dict()}).encode("utf-8")

            else:
                byt = json.dumps({'Success': False, 'Data': ''}).encode("utf-8")

            # send headers
            conn.send('HTTP/1.0 200 OK\r\n'.encode("utf-8"))
            conn.send("Content-Type: application/json\r\n".encode("utf-8"))
            sLenth = "Content-Length: " + str(len(byt))
            sLenth += "\r\n\r\n"
            conn.send(sLenth.encode("utf-8"))

            # send the acutal json
            conn.send(byt)


# Multithreaded Python server : TCP Server Socket Program Stub
TCP_IP = '0.0.0.0' 
TCP_PORT = 12345 
BUFFER_SIZE = 20  # Usually 1024, but we need quick response 

tcpServer = socket.socket(socket.AF_INET, socket.SOCK_STREAM) 
tcpServer.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1) 
tcpServer.bind((TCP_IP, TCP_PORT)) 
threads = [] 

while True: 
    tcpServer.listen(4) 
    print("Multithreaded Python server : Waiting for connections from TCP clients...\n\r")
    (conn, (ip,port)) = tcpServer.accept() 
    newthread = ClientThread(ip,port) 
    newthread.start() 
    threads.append(newthread) 

for t in threads: 
    t.join() 

启动Tomcat并转到/students.html,我得到了异常

@RequestMapping(value = "/students.html", method = RequestMethod.GET)
    public @ResponseBody
    List<Student> getStudentList(){

        Student student1 = new Student();
        student1.setStudentName("Leo");

        Student student2 = new Student();
        student2.setStudentName("Giggix");

        Student student3 = new Student();
        student3.setStudentName("John Cena");

        List<Student> students = new ArrayList<>();
        students.add(student1);
        students.add(student2);
        students.add(student3);

        return students;

    }

在我的pom.xml中,我具有以下依赖关系:

java.lang.IllegalArgumentException: No converter found for return value of type: class java.util.ArrayList

我已经尝试过类似问题中发布的所有解决方案,您有任何想法吗?

1 个答案:

答案 0 :(得分:-1)

List list = new ArrayList();

还要设置arraylist的数据类型。