List of usage examples for com.google.gson.reflect TypeToken isAssignableFrom
@Deprecated public boolean isAssignableFrom(TypeToken<?> token)
From source file:org.lanternpowered.server.script.json.ObjectTypeAdapterFactory.java
License:MIT License
@Nullable @Override//from ww w .j a va2 s . c o m public <T> TypeAdapter<T> create(Gson gson, TypeToken<T> type) { if (!type.isAssignableFrom(this.typeToken)) { return null; } final TypeAdapter<JsonElement> jsonElementTypeAdapter = gson.getAdapter(JsonElement.class); final TypeToken theTypeToken = type; return new TypeAdapter<T>() { @SuppressWarnings("unchecked") @Override public void write(JsonWriter out, T value) throws IOException { final JsonElement element = serialize((TypeToken<V>) theTypeToken, (V) value, gson); jsonElementTypeAdapter.write(out, element); } @SuppressWarnings("unchecked") @Override public T read(JsonReader in) throws IOException { final JsonElement element = jsonElementTypeAdapter.read(in); return (T) deserialize(theTypeToken, element, gson); } }; }