@Override
    public Collection<Label> deserialize(JsonElement element, Type type, JsonDeserializationContext context)
        throws JsonParseException
    {
        JsonObject obj = element.getAsJsonObject();
        JsonArray labels = obj.getAsJsonArray("labels");
        List<Label> values = new ArrayList<Label>();
        if(labels != null && labels.isJsonArray())
        {
            for(JsonElement label : labels)
                values.add(gson.fromJson(label, Label.class));
        }
        return values;
    }
@ Override public Collection < Label > deserialize ( JsonElement element , Type type , JsonDeserializationContext context ) throws JsonParseException { JsonObject obj = element . getAsJsonObject ( ) ; JsonArray labels = obj . getAsJsonArray ( "labels" ) ; List < Label > values = new ArrayList < Label > ( ) ; if ( labels != null && labels . isJsonArray ( ) ) { for ( JsonElement label : labels ) values . add ( gson . fromJson ( label , Label . class ) ) ; } return values ; }
Gson invokes this call-back method during deserialization when it encounters a field of the specified type.
@param element The Json data being deserialized
@param type The type of the Object to deserialize to
@param context The JSON deserialization context
@return The labels