Kill GsonInternalAccess. Clients to this were all broken because nobody was ever assigning INSTANCE.

This commit is contained in:
Jesse Wilson 2012-01-01 12:42:20 +00:00
parent 323dfa0af5
commit 796a381279
6 changed files with 5 additions and 75 deletions

View File

@ -20,7 +20,6 @@ import com.google.gson.Gson;
import com.google.gson.JsonElement; import com.google.gson.JsonElement;
import com.google.gson.TypeAdapter; import com.google.gson.TypeAdapter;
import com.google.gson.TypeAdapterFactory; import com.google.gson.TypeAdapterFactory;
import com.google.gson.internal.GsonInternalAccess;
import com.google.gson.internal.bind.JsonTreeReader; import com.google.gson.internal.bind.JsonTreeReader;
import com.google.gson.reflect.TypeToken; import com.google.gson.reflect.TypeToken;
import com.google.gson.stream.JsonReader; import com.google.gson.stream.JsonReader;
@ -59,7 +58,7 @@ public final class GraphTypeAdapterFactory implements TypeAdapterFactory {
return null; return null;
} }
final TypeAdapter<T> typeAdapter = GsonInternalAccess.INSTANCE.getNextAdapter(gson, this, type); final TypeAdapter<T> typeAdapter = gson.getNextAdapter(this, type);
final TypeAdapter<JsonElement> elementAdapter = gson.getAdapter(JsonElement.class); final TypeAdapter<JsonElement> elementAdapter = gson.getAdapter(JsonElement.class);
return new TypeAdapter<T>() { return new TypeAdapter<T>() {
@Override public void write(JsonWriter out, T value) throws IOException { @Override public void write(JsonWriter out, T value) throws IOException {

View File

@ -18,16 +18,12 @@ package com.google.gson.typeadapters;
import com.google.gson.Gson; import com.google.gson.Gson;
import com.google.gson.JsonElement; import com.google.gson.JsonElement;
import com.google.gson.JsonIOException;
import com.google.gson.JsonObject; import com.google.gson.JsonObject;
import com.google.gson.JsonParseException; import com.google.gson.JsonParseException;
import com.google.gson.JsonPrimitive; import com.google.gson.JsonPrimitive;
import com.google.gson.TypeAdapter; import com.google.gson.TypeAdapter;
import com.google.gson.TypeAdapterFactory; import com.google.gson.TypeAdapterFactory;
import com.google.gson.internal.GsonInternalAccess;
import com.google.gson.internal.Streams; import com.google.gson.internal.Streams;
import com.google.gson.internal.bind.JsonTreeWriter;
import com.google.gson.internal.bind.JsonTreeReader;
import com.google.gson.reflect.TypeToken; import com.google.gson.reflect.TypeToken;
import com.google.gson.stream.JsonReader; import com.google.gson.stream.JsonReader;
import com.google.gson.stream.JsonWriter; import com.google.gson.stream.JsonWriter;
@ -194,8 +190,7 @@ public final class RuntimeTypeAdapterFactory<T> implements TypeAdapterFactory {
final Map<Class<?>, TypeAdapter<?>> subtypeToDelegate final Map<Class<?>, TypeAdapter<?>> subtypeToDelegate
= new LinkedHashMap<Class<?>, TypeAdapter<?>>(); = new LinkedHashMap<Class<?>, TypeAdapter<?>>();
for (Map.Entry<String, Class<?>> entry : labelToSubtype.entrySet()) { for (Map.Entry<String, Class<?>> entry : labelToSubtype.entrySet()) {
TypeAdapter<?> delegate = GsonInternalAccess.INSTANCE TypeAdapter<?> delegate = gson.getNextAdapter(this, TypeToken.get(entry.getValue()));
.getNextAdapter(gson, this, TypeToken.get(entry.getValue()));
labelToDelegate.put(entry.getKey(), delegate); labelToDelegate.put(entry.getKey(), delegate);
subtypeToDelegate.put(entry.getValue(), delegate); subtypeToDelegate.put(entry.getValue(), delegate);
} }
@ -215,18 +210,7 @@ public final class RuntimeTypeAdapterFactory<T> implements TypeAdapterFactory {
throw new JsonParseException("cannot deserialize " + baseType + " subtype named " throw new JsonParseException("cannot deserialize " + baseType + " subtype named "
+ label + "; did you forget to register a subtype?"); + label + "; did you forget to register a subtype?");
} }
return fromJsonTree(delegate, jsonElement); return delegate.fromJsonTree(jsonElement);
}
// TODO: remove this when TypeAdapter.fromJsonTree() is public
private T fromJsonTree(TypeAdapter<T> delegate, JsonElement jsonTree) {
try {
JsonReader jsonReader = new JsonTreeReader(jsonTree);
jsonReader.setLenient(true);
return delegate.read(jsonReader);
} catch (IOException e) {
throw new JsonIOException(e);
}
} }
@Override public void write(JsonWriter out, T value) throws IOException { @Override public void write(JsonWriter out, T value) throws IOException {
@ -238,7 +222,7 @@ public final class RuntimeTypeAdapterFactory<T> implements TypeAdapterFactory {
throw new JsonParseException("cannot serialize " + srcType.getName() throw new JsonParseException("cannot serialize " + srcType.getName()
+ "; did you forget to register a subtype?"); + "; did you forget to register a subtype?");
} }
JsonObject jsonObject = toJsonTree(delegate, value).getAsJsonObject(); JsonObject jsonObject = delegate.toJsonTree(value).getAsJsonObject();
if (jsonObject.has(typeFieldName)) { if (jsonObject.has(typeFieldName)) {
throw new JsonParseException("cannot serialize " + srcType.getName() throw new JsonParseException("cannot serialize " + srcType.getName()
+ " because it already defines a field named " + typeFieldName); + " because it already defines a field named " + typeFieldName);
@ -250,18 +234,6 @@ public final class RuntimeTypeAdapterFactory<T> implements TypeAdapterFactory {
} }
Streams.write(clone, out); Streams.write(clone, out);
} }
// TODO: remove this when TypeAdapter.toJsonTree() is public
private JsonElement toJsonTree(TypeAdapter<T> delegate, T value) {
try {
JsonTreeWriter jsonWriter = new JsonTreeWriter();
jsonWriter.setLenient(true);
delegate.write(jsonWriter, value);
return jsonWriter.get();
} catch (IOException e) {
throw new JsonIOException(e);
}
}
}; };
} }
} }

View File

@ -18,7 +18,6 @@ package com.google.gson;
import com.google.gson.internal.ConstructorConstructor; import com.google.gson.internal.ConstructorConstructor;
import com.google.gson.internal.Excluder; import com.google.gson.internal.Excluder;
import com.google.gson.internal.GsonInternalAccess;
import com.google.gson.internal.Primitives; import com.google.gson.internal.Primitives;
import com.google.gson.internal.Streams; import com.google.gson.internal.Streams;
import com.google.gson.internal.bind.ArrayTypeAdapter; import com.google.gson.internal.bind.ArrayTypeAdapter;

View File

@ -17,7 +17,6 @@
package com.google.gson; package com.google.gson;
import com.google.gson.internal.$Gson$Preconditions; import com.google.gson.internal.$Gson$Preconditions;
import com.google.gson.internal.GsonInternalAccess;
import com.google.gson.internal.Streams; import com.google.gson.internal.Streams;
import com.google.gson.reflect.TypeToken; import com.google.gson.reflect.TypeToken;
import com.google.gson.stream.JsonReader; import com.google.gson.stream.JsonReader;

View File

@ -141,7 +141,7 @@ public final class Excluder implements TypeAdapterFactory, Cloneable {
TypeAdapter<T> d = delegate; TypeAdapter<T> d = delegate;
return d != null return d != null
? d ? d
: (delegate = GsonInternalAccess.INSTANCE.getNextAdapter(gson, Excluder.this, type)); : (delegate = gson.getNextAdapter(Excluder.this, type));
} }
}; };
} }

View File

@ -1,39 +0,0 @@
/*
* Copyright (C) 2011 Google Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.google.gson.internal;
import com.google.gson.Gson;
import com.google.gson.TypeAdapter;
import com.google.gson.TypeAdapterFactory;
import com.google.gson.reflect.TypeToken;
/**
* Internal-only APIs of Gson available only to other classes in Gson.
*/
public abstract class GsonInternalAccess {
public static GsonInternalAccess INSTANCE;
/**
* Returns a type adapter for {@code} type that isn't {@code skipPast}. This
* can be used for type adapters to compose other, simpler type adapters.
*
* @throws IllegalArgumentException if this GSON cannot serialize and
* deserialize {@code type}.
*/
public abstract <T> TypeAdapter<T> getNextAdapter(
Gson gson, TypeAdapterFactory skipPast, TypeToken<T> type);
}