I've seen a number of other similar looking questions, but I think there's a level of abstraction on top of those that makes the difference. Namely, I have a utility class with a static generic wrapper method to deserialize an object of generic type (unknown at build time):

```
public final class Utils {

    public static final Gson sGson = new Gson();

    public static synchronized <T> T fromJson(String doc) {
        return sGson.fromJson(doc, new TypeToken<T>(){}.getType());
    }
}

```

A simple class to test it on:

```
public class TestDocument {
    public TestDocument(String test) {
        this.test = test;
    }

    public String test;
}

```

This works well:

```
assertEquals(
   new TestDocument("test").test, 
   ((TestDocument) Utils.sGson.fromJson(
                      "{\"test\": \"test\"}", 
                      new TypeToken<TestDocument>(){}.getType())).test);

```

But what looks like an equivalent way to call this though the static generic utility method does not:

```
assertEquals(
   new TestDocument("test").test, 
   Utils.<TestDocument>fromJson("{\"test\": \"test\"}").test);

```

Throws the following exception:

> 
> java.lang.ClassCastException: com.google.gson.internal.LinkedTreeMap
>  cannot be cast to TestDocument
> 
> 
> 

Is there a way to make it work through the generic method?