Merge pull request #63 from ZhangYu0418/4.0-dev
fix: 修复接口返回包含空字符串对象引起的反序列化失败
This commit is contained in:
commit
4912e6366d
|
|
@ -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.SerializedName
|
||||
import com.huanchengfly.tieba.post.api.adapters.ContentMsgAdapter
|
||||
import com.huanchengfly.tieba.post.api.adapters.PortraitAdapter
|
||||
import com.huanchengfly.tieba.post.api.adapters.SubPostListAdapter
|
||||
import com.huanchengfly.tieba.post.models.BaseBean
|
||||
|
|
@ -158,6 +159,7 @@ class ThreadContentBean : BaseBean() {
|
|||
|
||||
class OriginThreadInfo {
|
||||
val title: String? = null
|
||||
@JsonAdapter(ContentMsgAdapter::class)
|
||||
val content: List<ContentBean>? = null
|
||||
}
|
||||
|
||||
|
|
@ -166,6 +168,7 @@ class ThreadContentBean : BaseBean() {
|
|||
val title: String? = null
|
||||
val floor: String? = null
|
||||
val time: String? = null
|
||||
@JsonAdapter(ContentMsgAdapter::class)
|
||||
val content: List<ContentBean>? = null
|
||||
val agree: AgreeBean? = null
|
||||
|
||||
|
|
|
|||
Loading…
Reference in New Issue