@Override
    public Collection<Metric> deserialize(JsonElement element, Type type, JsonDeserializationContext context)
        throws JsonParseException
    {
        JsonObject obj = element.getAsJsonObject();
        JsonArray metrics = obj.getAsJsonArray("metrics");
        List<Metric> values = new ArrayList<Metric>();
        if(metrics != null && metrics.isJsonArray())
        {
            for(JsonElement metric : metrics)
                values.add(gson.fromJson(metric, Metric.class));
        }
        return values;
    }
@ Override public Collection < Metric > deserialize ( JsonElement element , Type type , JsonDeserializationContext context ) throws JsonParseException { JsonObject obj = element . getAsJsonObject ( ) ; JsonArray metrics = obj . getAsJsonArray ( "metrics" ) ; List < Metric > values = new ArrayList < Metric > ( ) ; if ( metrics != null && metrics . isJsonArray ( ) ) { for ( JsonElement metric : metrics ) values . add ( gson . fromJson ( metric , Metric . 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 metrics