7

I'm trying to consume a REST service in an Android application, but am having problems in serializing an ArrayList:

My RESTful service returns:

enter image description here

My Android application receives:

enter image description here

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?

falvojr
  • 3,060
  • 4
  • 31
  • 54
  • 1
    possible duplicate of [Gson TypeToken with dynamic Arraylist's type](http://stackoverflow.com/questions/20773850/gson-typetoken-with-dynamic-arraylists-type) – Sotirios Delimanolis Mar 30 '14 at 04:26

1 Answers1

0

Can you please try to change the gradle version to an updated version and check whether the issue is resolved.

I too had the same issue and it got resolved when I changed the gradle version from 1.5.0 to 2.1.0

Eldhose M Babu
  • 14,382
  • 8
  • 39
  • 44