Skip to content

Commit

Permalink
Kill GsonInternalAccess. Clients to this were all broken because nobo…
Browse files Browse the repository at this point in the history
…dy was ever assigning INSTANCE.
  • Loading branch information
swankjesse committed Jan 1, 2012
1 parent 323dfa0 commit 796a381
Show file tree
Hide file tree
Showing 6 changed files with 5 additions and 75 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@
import com.google.gson.JsonElement;
import com.google.gson.TypeAdapter;
import com.google.gson.TypeAdapterFactory;
import com.google.gson.internal.GsonInternalAccess;
import com.google.gson.internal.bind.JsonTreeReader;
import com.google.gson.reflect.TypeToken;
import com.google.gson.stream.JsonReader;
Expand Down Expand Up @@ -59,7 +58,7 @@ public <T> TypeAdapter<T> create(Gson gson, TypeToken<T> type) {
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);
return new TypeAdapter<T>() {
@Override public void write(JsonWriter out, T value) throws IOException {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,16 +18,12 @@

import com.google.gson.Gson;
import com.google.gson.JsonElement;
import com.google.gson.JsonIOException;
import com.google.gson.JsonObject;
import com.google.gson.JsonParseException;
import com.google.gson.JsonPrimitive;
import com.google.gson.TypeAdapter;
import com.google.gson.TypeAdapterFactory;
import com.google.gson.internal.GsonInternalAccess;
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.stream.JsonReader;
import com.google.gson.stream.JsonWriter;
Expand Down Expand Up @@ -194,8 +190,7 @@ public <T> TypeAdapter<T> create(Gson gson, TypeToken<T> type) {
final Map<Class<?>, TypeAdapter<?>> subtypeToDelegate
= new LinkedHashMap<Class<?>, TypeAdapter<?>>();
for (Map.Entry<String, Class<?>> entry : labelToSubtype.entrySet()) {
TypeAdapter<?> delegate = GsonInternalAccess.INSTANCE
.getNextAdapter(gson, this, TypeToken.get(entry.getValue()));
TypeAdapter<?> delegate = gson.getNextAdapter(this, TypeToken.get(entry.getValue()));
labelToDelegate.put(entry.getKey(), delegate);
subtypeToDelegate.put(entry.getValue(), delegate);
}
Expand All @@ -215,18 +210,7 @@ public <T> TypeAdapter<T> create(Gson gson, TypeToken<T> type) {
throw new JsonParseException("cannot deserialize " + baseType + " subtype named "
+ label + "; did you forget to register a subtype?");
}
return fromJsonTree(delegate, 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);
}
return delegate.fromJsonTree(jsonElement);
}

@Override public void write(JsonWriter out, T value) throws IOException {
Expand All @@ -238,7 +222,7 @@ private T fromJsonTree(TypeAdapter<T> delegate, JsonElement jsonTree) {
throw new JsonParseException("cannot serialize " + srcType.getName()
+ "; did you forget to register a subtype?");
}
JsonObject jsonObject = toJsonTree(delegate, value).getAsJsonObject();
JsonObject jsonObject = delegate.toJsonTree(value).getAsJsonObject();
if (jsonObject.has(typeFieldName)) {
throw new JsonParseException("cannot serialize " + srcType.getName()
+ " because it already defines a field named " + typeFieldName);
Expand All @@ -250,18 +234,6 @@ private T fromJsonTree(TypeAdapter<T> delegate, JsonElement jsonTree) {
}
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);
}
}
};
}
}
1 change: 0 additions & 1 deletion gson/src/main/java/com/google/gson/Gson.java
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@

import com.google.gson.internal.ConstructorConstructor;
import com.google.gson.internal.Excluder;
import com.google.gson.internal.GsonInternalAccess;
import com.google.gson.internal.Primitives;
import com.google.gson.internal.Streams;
import com.google.gson.internal.bind.ArrayTypeAdapter;
Expand Down
1 change: 0 additions & 1 deletion gson/src/main/java/com/google/gson/TreeTypeAdapter.java
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@
package com.google.gson;

import com.google.gson.internal.$Gson$Preconditions;
import com.google.gson.internal.GsonInternalAccess;
import com.google.gson.internal.Streams;
import com.google.gson.reflect.TypeToken;
import com.google.gson.stream.JsonReader;
Expand Down
2 changes: 1 addition & 1 deletion gson/src/main/java/com/google/gson/internal/Excluder.java
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,7 @@ private TypeAdapter<T> delegate() {
TypeAdapter<T> d = delegate;
return d != null
? d
: (delegate = GsonInternalAccess.INSTANCE.getNextAdapter(gson, Excluder.this, type));
: (delegate = gson.getNextAdapter(Excluder.this, type));
}
};
}
Expand Down

This file was deleted.

0 comments on commit 796a381

Please sign in to comment.