Fixed eclipse warnings.
This commit is contained in:
parent
b5f8ef6e16
commit
2780a2a9bf
@ -730,7 +730,6 @@ public final class Gson {
|
||||
* @throws JsonSyntaxException if json is not a valid representation for an object of type typeOfT
|
||||
* @since 1.3
|
||||
*/
|
||||
@SuppressWarnings("unchecked")
|
||||
public <T> T fromJson(JsonElement json, Type typeOfT) throws JsonSyntaxException {
|
||||
if (json == null) {
|
||||
return null;
|
||||
|
@ -36,7 +36,7 @@ public class JsonDeserializationContext {
|
||||
/**
|
||||
* TODO: remove this from the public API
|
||||
*/
|
||||
@SuppressWarnings("unchecked") @Deprecated
|
||||
@Deprecated
|
||||
public <T> T construct(Type type) {
|
||||
throw new UnsupportedOperationException();
|
||||
}
|
||||
@ -57,12 +57,10 @@ public class JsonDeserializationContext {
|
||||
* @return An object of type typeOfT.
|
||||
* @throws JsonParseException if the parse tree does not contain expected data.
|
||||
*/
|
||||
@SuppressWarnings("unchecked")
|
||||
public <T> T deserialize(JsonElement json, Type typeOfT) throws JsonParseException {
|
||||
return gson.fromJson(json, typeOfT);
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
public <T> T deserializeDefault(JsonElement json, Type typeOfT) throws JsonParseException {
|
||||
throw new UnsupportedOperationException();
|
||||
}
|
||||
|
@ -156,9 +156,11 @@ public final class ConstructorConstructor {
|
||||
final Type type, final Class<? super T> rawType) {
|
||||
return new ObjectConstructor<T>() {
|
||||
private final UnsafeAllocator unsafeAllocator = UnsafeAllocator.create();
|
||||
@SuppressWarnings("unchecked")
|
||||
public T construct() {
|
||||
try {
|
||||
return (T) unsafeAllocator.newInstance(rawType);
|
||||
Object newInstance = unsafeAllocator.newInstance(rawType);
|
||||
return (T) newInstance;
|
||||
} catch (Exception e) {
|
||||
throw new RuntimeException(("Unable to invoke no-args constructor for " + type + ". "
|
||||
+ "Register an InstanceCreator with Gson for this type may fix this problem."), e);
|
||||
|
@ -34,6 +34,7 @@ import com.google.gson.stream.JsonWriter;
|
||||
*/
|
||||
public final class ArrayTypeAdapter<E> extends TypeAdapter<Object> {
|
||||
public static final Factory FACTORY = new Factory() {
|
||||
@SuppressWarnings("unchecked")
|
||||
public <T> TypeAdapter<T> create(MiniGson context, TypeToken<T> typeToken) {
|
||||
Type type = typeToken.getType();
|
||||
if (!(type instanceof GenericArrayType || type instanceof Class && ((Class<?>) type).isArray())) {
|
||||
@ -78,6 +79,7 @@ public final class ArrayTypeAdapter<E> extends TypeAdapter<Object> {
|
||||
return array;
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
@Override public void write(JsonWriter writer, Object array) throws IOException {
|
||||
if (array == null) {
|
||||
writer.nullValue(); // TODO: better policy here?
|
||||
|
@ -22,6 +22,7 @@ final class Reflection {
|
||||
/**
|
||||
* Finds a compatible runtime type if it is more specific
|
||||
*/
|
||||
@SuppressWarnings("unchecked")
|
||||
public static Type getRuntimeTypeIfMoreSpecific(Type type, Object value) {
|
||||
if (value != null
|
||||
&& (type == Object.class || type instanceof TypeVariable || type instanceof Class<?>)) {
|
||||
|
@ -27,6 +27,7 @@ public final class ObjectTypeAdapterTest extends TestCase {
|
||||
private final MiniGson gson = new MiniGson.Builder().build();
|
||||
private final TypeAdapter<Object> adapter = gson.getAdapter(Object.class);
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
public void testDeserialize() throws Exception {
|
||||
Map<?, ?> map = (Map) adapter.fromJson("{a: 5, b: [1, 2, null], c: {x: y}}");
|
||||
assertEquals(5.0, map.get("a"));
|
||||
@ -35,6 +36,7 @@ public final class ObjectTypeAdapterTest extends TestCase {
|
||||
assertEquals(3, map.size());
|
||||
}
|
||||
|
||||
@SuppressWarnings("unused")
|
||||
public void testSerialize() throws Exception {
|
||||
Object object = new Object() {
|
||||
Object a = 5;
|
||||
|
@ -208,6 +208,7 @@ public class CollectionTest extends TestCase {
|
||||
assertTrue(json.contains(bag1.getExpectedJson()));
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
public void testRawCollectionDeserializationNotAlllowed() {
|
||||
String json = "[0,1,2,3,4,5,6,7,8,9]";
|
||||
Collection integers = gson.fromJson(json, Collection.class);
|
||||
|
Loading…
Reference in New Issue
Block a user