I'm trying to consume a REST service in an Android application, but am having problems in serializing an ArrayList:
My RESTful service returns:
My Android application receives:
I'm using Gson library for serialization of my objects and certainly the problem is related to it. In this sense I tried to make Serializer as follows:
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);
}
}
Registered the apapter (registerTypeAdapter(ArrayList.class, new MySerializer<Object>())
), but this not work...
Could anyone help me please?