Spring mvc,无法读取JSON:无法从START_OBJECT标记中反序列化java.util.Vector的实例

时间:2014-06-19 18:41:58

标签: java json spring

好的,我试图收到这种JSON

[{"username":"pippo","password":"bla"},{"username":"pluto","password":"bla"},{"username":"topolino","password":"bla"}]

但是我收到了这个错误:

    Resolving exception from handler [public void sequenziatore.server.presenter.LoginController.CheckLogin(java.util.Vector<sequenziatore.server.presenter.Utente>)]: org.springframework.http.converter.HttpMessageNotReadableException: Could not read JSON: Can not deserialize instance of java.util.Vector out of START_OBJECT token
 at [Source: org.apache.catalina.connector.CoyoteInputStream@68c40ef9; line: 1, column: 1]; nested exception is org.codehaus.jackson.map.JsonMappingException: Can not deserialize instance of java.util.Vector out of START_OBJECT token
 at [Source: org.apache.catalina.connector.CoyoteInputStream@68c40ef9; line: 1, column: 1]
Resolving exception from handler [public void sequenziatore.server.presenter.LoginController.CheckLogin(java.util.Vector<sequenziatore.server.presenter.Utente>)]: org.springframework.http.converter.HttpMessageNotReadableException: Could not read JSON: Can not deserialize instance of java.util.Vector out of START_OBJECT token
 at [Source: org.apache.catalina.connector.CoyoteInputStream@68c40ef9; line: 1, column: 1]; nested exception is org.codehaus.jackson.map.JsonMappingException: Can not deserialize instance of java.util.Vector out of START_OBJECT token
 at [Source: org.apache.catalina.connector.CoyoteInputStream@68c40ef9; line: 1, column: 1]
Resolving exception from handler [public void sequenziatore.server.presenter.LoginController.CheckLogin(java.util.Vector<sequenziatore.server.presenter.Utente>)]: org.springframework.http.converter.HttpMessageNotReadableException: Could not read JSON: Can not deserialize instance of java.util.Vector out of START_OBJECT token
 at [Source: org.apache.catalina.connector.CoyoteInputStream@68c40ef9; line: 1, column: 1]; nested exception is org.codehaus.jackson.map.JsonMappingException: Can not deserialize instance of java.util.Vector out of START_OBJECT token
 at [Source: org.apache.catalina.connector.CoyoteInputStream@68c40ef9; line: 1, column: 1]

这是我使用的控制器:

@Controller
@RequestMapping(value = "/login")
public class LoginController {
    @RequestMapping(method=RequestMethod.POST, consumes = "application/json", produces = "application/json")
    @ResponseBody
    public void CheckLogin(@RequestBody Vector<Utente> vec) {
    .....
    }

我试图用Utente []而不是Vector来改变我收到的类型,但没有改变,真正的问题是我不明白错误是什么...... 这是我收到的JSON,如果我更改字符串中的接收类型并打印它...

{"0":{"username":"pippo","password":"bla"},"1":{"username":"pluto","password":"bla"},"2":{"username":"topolino","password":"bla"}}

这是Utente课程

public class Utente {
    private String username=null;
    private String password=null;

    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 Utente(){}
}

0 个答案:

没有答案