5
我想在Android應用程序使用REST服務,但我有在序列化一個ArrayList問題:GSON序列化到LinkedTreeMap,而不是我的實體
我的RESTful服務回報:
我的Android應用程序接收:
我正在使用Gson庫對我的對象進行序列化,當然這個問題與它有關。在這個意義上,我試圖讓串行如下:
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);
}
}
註冊apapter(registerTypeAdapter(ArrayList.class, new MySerializer<Object>())
),但這不工作...
誰能幫幫我好嗎?
可能重複http://stackoverflow.com /問題/ 20773850/GSON-typetoken與 - 動態的ArrayList型) –