简体   繁体   中英

Json data through POSTMAN rest client in chrome

I am trying to test the backend service through postman rest client with json data and POST method.

First 2 parameters are arraylist and rest all are either String or Integer The data i am passing is below:

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

my controller to accept this as below:

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){
.....
}

After submitting i am getting the below error: org.springframework.http.converter.HttpMessageNotReadableException: Could not read JSON: Can not deserialize instance of java.util.ArrayList out of START_OBJECT token at [Source: org.apache.catalina.connector.CoyoteInputStream@4c352e08; line: 1, column: 1]; nested exception is org.codehaus.jackson.map.JsonMappingException: Can not deserialize instance of java.util.ArrayList out of START_OBJECT token at [Source: org.apache.catalina.connector.CoyoteInputStream@4c352e08; line: 1, column: 1]

Any idea how to pass the array & other params.

Define a java bean as follows -

 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; } } 

modify the method inside controller as follows -

public WatchDTO add(@RequestBody UserStat userStat){ }

public WatchDTO add(@RequestBody UserStat userStat){ }

This should work

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM