【发布时间】:2021-12-26 18:18:16
【问题描述】:
在 GET 中检索信息时,我得到了正确的响应。现在,我正在尝试使用 Post 调用将一些数据发送回服务器。但是当我这样做时,我会得到classCastException
这里是模型类
public class Polygon implements Parcelable
{
@SerializedName("type")
@Expose
private String type;
@SerializedName("coordinates")
@Expose
private List<List<List<Double>>> coordinates = new ArrayList<>();
public final static Creator<Polygon> CREATOR = new Creator<Polygon>() {
@SuppressWarnings({
"unchecked"
})
public Polygon createFromParcel(android.os.Parcel in) {
return new Polygon(in);
}
public Polygon[] newArray(int size) {
return (new Polygon[size]);
}
};
protected Polygon(android.os.Parcel in) {
this.type = ((String) in.readValue((String.class.getClassLoader())));
in.readList(this.coordinates, (List.class.getClassLoader()));
}
public Polygon() {
}
public String getType() {
return type;
}
public void setType(String type) {
this.type = type;
}
public List<List<List<Double>>> getCoordinates() {
return coordinates;
}
public void setCoordinates(List<List<List<Double>>> coordinates) {
this.coordinates = coordinates;
}
public void writeToParcel(android.os.Parcel dest, int flags) {
dest.writeValue(type);
dest.writeList(coordinates);
}
public int describeContents() {
return 0;
}
}
这是我试图检索并稍后发回的 json。
{"polygon": {
"type": "Polygon",
"coordinates": [
[
[
-105.18367,
39.54363
],
[
-105.18367,
39.98435
],
[
-104.33773,
39.98435
],
[
-104.33773,
39.54363
],
[
-105.18367,
39.54363
]
]
]
}
}
为此我得到java.lang.ClassCastException: java.lang.Double cannot be cast to java.util.Collection。
我尝试将其转换为单独的类以将其用作CREATOR,但随后 GET 调用失败。
任何帮助都会很棒!
【问题讨论】:
标签: java android parcelable