2014-03-26 48 views
0

我想通過郵遞員休息客戶端與JSON數據和POST方法測試後端服務。JSON數據通過POSTMAN休息客戶端在鉻

首先兩個參數是ArrayList和其餘全部或者是字符串或整數 我傳遞的數據低於:

{ 
"watchUsers":["user1"], 
"msgUsers":["user2"], 
"status":1, 
"sendTime":319876, 
"compId":"turbo", 
"workId":"ts", 
"startId":"engine", 
"endId":"restore", 
"msg":"Completed Successfully" 
} 

我的控制器,如下接受這一點:

public WatchDTO add(@RequestBody ArrayList<String> watchUsers,@RequestBody ArrayList<String> msgUsers, Integer status, Integer sendTime, String compId, String workId, String startId, String endId, String msg){ 
..... 
} 

提交後我收到以下錯誤: org.springframework.http.converter.HttpMessageNotReadableException:無法讀取JSON:無法將java.util.ArrayList的實例反序列化爲START_OBJECT標記 at [Source:[email protected];行:1,列:1];嵌套的異常是org.codehaus.jackson.map.JsonMappingException:無法將[java.util.ArrayList的實例反序列化爲START_OBJECT標記 at [Source:[email protected];行:1,列:1]

任何想法如何通過數組&其他params。

+0

提供一個DTO和檢索'watchUsers'領域。 –

回答

0

定義一個Java bean如下 -

import java.util.ArrayList; 

public class UserStat { 
    ArrayList<String> watchUsers; 
    ArrayList<String> msgUsers; 
    int status; 
    int sendTime; 
    String compId; 
    String workId; 
    String startId; 
    String endId; 
    String msg; 

    public ArrayList<String> getWatchUsers() { 
     return watchUsers; 
    } 

    public void setWatchUsers(ArrayList<String> watchUsers) { 
     this.watchUsers = watchUsers; 
    } 

    public ArrayList<String> getMsgUsers() { 
     return msgUsers; 
    } 

    public void setMsgUsers(ArrayList<String> msgUsers) { 
     this.msgUsers = msgUsers; 
    } 

    public int getStatus() { 
     return status; 
    } 

    public void setStatus(int status) { 
     this.status = status; 
    } 

    public int getSendTime() { 
     return sendTime; 
    } 

    public void setSendTime(int sendTime) { 
     this.sendTime = sendTime; 
    } 

    public String getCompId() { 
     return compId; 
    } 

    public void setCompId(String compId) { 
     this.compId = compId; 
    } 

    public String getWorkId() { 
     return workId; 
    } 

    public void setWorkId(String workId) { 
     this.workId = workId; 
    } 

    public String getStartId() { 
     return startId; 
    } 

    public void setStartId(String startId) { 
     this.startId = startId; 
    } 

    public String getEndId() { 
     return endId; 
    } 

    public void setEndId(String endId) { 
     this.endId = endId; 
    } 

    public String getMsg() { 
     return msg; 
    } 

    public void setMsg(String msg) { 
     this.msg = msg; 
    } 

} 

修改內部控制的方法如下 -

public WatchDTO add(@RequestBody UserStat userStat){

}

這應該工作