для списка
@JsonIgnoreProperties(ignoreUnknown = true)
public class LolMatch {
private long gameId;
private String role;
private int season;
private String platformID;
private int champion;
private int queue;
private String lane;
private long timestamp;
public long getGameId() {
return gameId;
}
public void setGameId(long gameId) {
this.gameId = gameId;
}
public String getRole() {
return role;
}
public void setRole(String role) {
this.role = role;
}
public int getSeason() {
return season;
}
public void setSeason(int season) {
this.season = season;
}
public String getPlatformID() {
return platformID;
}
public void setPlatformID(String platformID) {
this.platformID = platformID;
}
public int getChampion() {
return champion;
}
public void setChampion(int champion) {
this.champion = champion;
}
public int getQueue() {
return queue;
}
public void setQueue(int queue) {
this.queue = queue;
}
public String getLane() {
return lane;
}
public void setLane(String lane) {
this.lane = lane;
}
public long getTimestamp() {
return timestamp;
}
public void setTimestamp(long timestamp) {
this.timestamp = timestamp;
}
}
для ответа
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
import java.util.ArrayList;
import java.util.List;
@JsonIgnoreProperties(ignoreUnknown = true)
public class LolMatchList {
private int startIndex;
private int totalGames;
private int endIndex;
List<LolMatch> matches;
public LolMatchList() {
matches = new ArrayList<LolMatch>();
}
public int getStartIndex() {
return startIndex;
}
public void setStartIndex(int startIndex) {
this.startIndex = startIndex;
}
public int getTotalGames() {
return totalGames;
}
public void setTotalGames(int totalGames) {
this.totalGames = totalGames;
}
public int getEndIndex() {
return endIndex;
}
public void setEndIndex(int endIndex) {
this.endIndex = endIndex;
}
public List<LolMatch> getMatches() {
return matches;
}
public void setMatches(List<LolMatch> matches) {
this.matches = matches;
}
}
Пример ответа такой
{
"startIndex": 0,
"totalGames": 151,
"endIndex": 100,
"matches": [
{
"gameId": 1,
"role": "DUO",
"season": 13,
"platformId": "xx",
"champion": 13,
"queue": 450,
"lane": "MID",
"timestamp": 1589718112737
},
{
"gameId": 2,
"role": "SOLO",
"season": 13,
"platformId": "xx",
"champion": 7,
"queue": 450,
"lane": "BOTTOM",
"timestamp": 1589716370234
},
{
"gameId": 11,
"role": "DUO_SUPPORT",
"season": 13,
"platformId": "xx",
"champion": 55,
"queue": 450,
"lane": "MID",
"timestamp": 1589714562139
}
]
}
Вот как я получаю ответ
URL url = новый URL (request_url);
BufferedReader br = new BufferedReader (new InputStreamReader (url.openStream ()));
JSONObject jAns = new JSONObject (br.readLine ( ));
JSONArray match = jAns.getJSONArray ("соответствует");
Мне не удалось сопоставить ответ с этими классами, LolMatch и LolMatchList. Есть ли способ сделать это автоматически или я должен проанализировать данные и go через ответ, чтобы создать объекты самостоятельно? Спасибо