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

Visit the link http://localhost:8080/test/user, if the error java.lang.IllegalArgumentException: No converter found for return value of type is reported, the getter/setter method is missing in the UserEntity class
<!--jackson-->
        <dependency>
            <groupId>com.fasterxml.jackson.core</groupId>
            <artifactId>jackson-core</artifactId>
            <version>2.7.0</version>
        </dependency>
        <dependency>
            <groupId>com.fasterxml.jackson.core</groupId>
            <artifactId>jackson-databind</artifactId>
            <version>2.7.0</version>
        </dependency>
        <dependency>
            <groupId>com.fasterxml.jackson.core</groupId>
            <artifactId>jackson-annotations</artifactId>
            <version>2.7.0</version>
        </dependency>

package com.hundsun.test.entity;

public class UserEntity {

    private String username;
    private String password;

    public String getUsername() {
        return username;
    }

    public void setUsername(String username) {
        this.username = username;
    }

    public String getPassword() {
        return password;
    }

    public void setPassword(String password) {
        this.password = password;
    }

    public UserEntity(){

    }

    public UserEntity(String username, String password){
        this.username = username;
        this.password = password;
    }
}

package com.hundsun.test.controller;

import com.hundsun.test.entity.UserEntity;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

@Controller
@RequestMapping("/test")//Unified entry for all interfaces under Controller
public class UserController {

    //map an action
    @RequestMapping("/user")
    @ResponseBody//Indicates that the return content is directly output, and no jsp or html jump is performed. This example is to write an interface, and json is directly returned here.
    public UserEntity getUser() {
        //Create a UserEntity and return it directly. The jackson previously configured in web.xml will convert the user object to json output
        UserEntity user = new UserEntity("jack", "123456");
        return user;
    }

}

Guess you like

Origin http://10.200.1.11:23101/article/api/json?id=326826238&siteId=291194637