fix: 修复接口返回包含空字符串对象引起的反序列化失败
This commit is contained in:
parent
5fee614442
commit
95ff492c00
|
|
@ -0,0 +1,27 @@
|
||||||
|
package com.huanchengfly.tieba.post.api.adapters;
|
||||||
|
|
||||||
|
import com.google.gson.JsonDeserializationContext;
|
||||||
|
import com.google.gson.JsonDeserializer;
|
||||||
|
import com.google.gson.JsonElement;
|
||||||
|
import com.google.gson.JsonParseException;
|
||||||
|
import com.huanchengfly.tieba.post.api.models.ThreadContentBean;
|
||||||
|
|
||||||
|
import java.lang.reflect.Type;
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
public class ContentMsgAdapter implements JsonDeserializer<List<ThreadContentBean.ContentBean>> {
|
||||||
|
@Override
|
||||||
|
public List<ThreadContentBean.ContentBean> deserialize(JsonElement json, Type typeOfT, JsonDeserializationContext context) throws JsonParseException {
|
||||||
|
List<ThreadContentBean.ContentBean> list = new ArrayList<>();
|
||||||
|
if(json.isJsonArray()){
|
||||||
|
json.getAsJsonArray().forEach(element->{
|
||||||
|
if(element.isJsonObject()){
|
||||||
|
list.add(context.deserialize(element,ThreadContentBean.ContentBean.class));
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
return list;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -2,6 +2,7 @@ package com.huanchengfly.tieba.post.api.models
|
||||||
|
|
||||||
import com.google.gson.annotations.JsonAdapter
|
import com.google.gson.annotations.JsonAdapter
|
||||||
import com.google.gson.annotations.SerializedName
|
import com.google.gson.annotations.SerializedName
|
||||||
|
import com.huanchengfly.tieba.post.api.adapters.ContentMsgAdapter
|
||||||
import com.huanchengfly.tieba.post.api.adapters.PortraitAdapter
|
import com.huanchengfly.tieba.post.api.adapters.PortraitAdapter
|
||||||
import com.huanchengfly.tieba.post.api.adapters.SubPostListAdapter
|
import com.huanchengfly.tieba.post.api.adapters.SubPostListAdapter
|
||||||
import com.huanchengfly.tieba.post.models.BaseBean
|
import com.huanchengfly.tieba.post.models.BaseBean
|
||||||
|
|
@ -158,6 +159,7 @@ class ThreadContentBean : BaseBean() {
|
||||||
|
|
||||||
class OriginThreadInfo {
|
class OriginThreadInfo {
|
||||||
val title: String? = null
|
val title: String? = null
|
||||||
|
@JsonAdapter(ContentMsgAdapter::class)
|
||||||
val content: List<ContentBean>? = null
|
val content: List<ContentBean>? = null
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -166,6 +168,7 @@ class ThreadContentBean : BaseBean() {
|
||||||
val title: String? = null
|
val title: String? = null
|
||||||
val floor: String? = null
|
val floor: String? = null
|
||||||
val time: String? = null
|
val time: String? = null
|
||||||
|
@JsonAdapter(ContentMsgAdapter::class)
|
||||||
val content: List<ContentBean>? = null
|
val content: List<ContentBean>? = null
|
||||||
val agree: AgreeBean? = null
|
val agree: AgreeBean? = null
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue