fal*_*ojr 6 java rest serialization android gson
我正在尝试在Android应用程序中使用REST服务,但在序列化ArrayList时遇到问题:
我的RESTful服务返回:

我的Android应用程序收到:

我正在使用Gson库来序列化我的对象,当然问题与它有关.从这个意义上讲,我尝试按如下方式制作Serializer:
public class MySerializer<E>
implements JsonSerializer<Collection<E>>, JsonDeserializer<Collection<E>> {
@Override
public Collection<E> deserialize(JsonElement json, Type typeOfT,
JsonDeserializationContext context) throws JsonParseException {
Type type = new TypeToken<List<E>>(){}.getType();
return context.deserialize(json, type);
}
@Override
public JsonElement serialize(Collection<E> src, Type typeOfSrc,
JsonSerializationContext context) {
Type type = new TypeToken<List<E>>(){}.getType();
return context.serialize(src, type);
}
}
Run Code Online (Sandbox Code Playgroud)
注册apapter(registerTypeAdapter(ArrayList.class, new MySerializer<Object>())),但这不起作用......
有人可以帮帮我吗?
| 归档时间: |
|
| 查看次数: |
1168 次 |
| 最近记录: |