diff --git a/extras/pom.xml b/extras/pom.xml
index 51a05de6..20ff30ea 100644
--- a/extras/pom.xml
+++ b/extras/pom.xml
@@ -40,7 +40,7 @@
com.google.code.gson
gson
- 2.1-SNAPSHOT
+ 2.2-SNAPSHOT
compile
diff --git a/gson/src/main/java/com/google/gson/Gson.java b/gson/src/main/java/com/google/gson/Gson.java
index 93506bbd..4f33b726 100644
--- a/gson/src/main/java/com/google/gson/Gson.java
+++ b/gson/src/main/java/com/google/gson/Gson.java
@@ -363,29 +363,27 @@ public final class Gson {
}
}
- static {
- GsonInternalAccess.INSTANCE = new GsonInternalAccess() {
- @Override public TypeAdapter getNextAdapter(
- Gson gson, TypeAdapterFactory skipPast, TypeToken type) {
- boolean skipPastFound = false;
+ /**
+ * TODO: needs documentation
+ * @since 2.2
+ */
+ public TypeAdapter getNextAdapter(TypeAdapterFactory skipPast, TypeToken type) {
+ boolean skipPastFound = false;
- for (TypeAdapterFactory factory : gson.factories) {
- if (!skipPastFound) {
- if (factory == skipPast) {
- skipPastFound = true;
- }
- continue;
- }
-
- TypeAdapter candidate = factory.create(gson, type);
- if (candidate != null) {
- return candidate;
- }
+ for (TypeAdapterFactory factory : factories) {
+ if (!skipPastFound) {
+ if (factory == skipPast) {
+ skipPastFound = true;
}
-
- throw new IllegalArgumentException("GSON cannot serialize " + type);
+ continue;
}
- };
+
+ TypeAdapter candidate = factory.create(this, type);
+ if (candidate != null) {
+ return candidate;
+ }
+ }
+ throw new IllegalArgumentException("GSON cannot serialize " + type);
}
/**
diff --git a/gson/src/main/java/com/google/gson/TreeTypeAdapter.java b/gson/src/main/java/com/google/gson/TreeTypeAdapter.java
index 642e1c1b..c9929069 100644
--- a/gson/src/main/java/com/google/gson/TreeTypeAdapter.java
+++ b/gson/src/main/java/com/google/gson/TreeTypeAdapter.java
@@ -76,7 +76,7 @@ final class TreeTypeAdapter extends TypeAdapter {
TypeAdapter d = delegate;
return d != null
? d
- : (delegate = GsonInternalAccess.INSTANCE.getNextAdapter(gson, skipPast, typeToken));
+ : (delegate = gson.getNextAdapter(skipPast, typeToken));
}
/**
diff --git a/gson/src/main/java/com/google/gson/TypeAdapter.java b/gson/src/main/java/com/google/gson/TypeAdapter.java
index c4325708..9426edf7 100644
--- a/gson/src/main/java/com/google/gson/TypeAdapter.java
+++ b/gson/src/main/java/com/google/gson/TypeAdapter.java
@@ -135,8 +135,9 @@ public abstract class TypeAdapter {
* writing.
*
* @param value the Java object to convert. May be null.
+ * @since 2.2
*/
- /*public*/ final void toJson(Writer out, T value) throws IOException {
+ public final void toJson(Writer out, T value) throws IOException {
JsonWriter writer = new JsonWriter(out);
write(writer, value);
}
@@ -208,8 +209,9 @@ public abstract class TypeAdapter {
* writing.
*
* @param value the Java object to convert. May be null.
+ * @since 2.2
*/
- /*public*/ final String toJson(T value) throws IOException {
+ public final String toJson(T value) throws IOException {
StringWriter stringWriter = new StringWriter();
toJson(stringWriter, value);
return stringWriter.toString();
@@ -220,8 +222,9 @@ public abstract class TypeAdapter {
*
* @param value the Java object to convert. May be null.
* @return the converted JSON tree. May be {@link JsonNull}.
+ * @since 2.2
*/
- /*public*/ final JsonElement toJsonTree(T value) {
+ public final JsonElement toJsonTree(T value) {
try {
JsonTreeWriter jsonWriter = new JsonTreeWriter();
jsonWriter.setLenient(true);
@@ -247,8 +250,9 @@ public abstract class TypeAdapter {
* {@code JsonReader} and call {@link #read(JsonReader)} for lenient reading.
*
* @return the converted Java object. May be null.
+ * @since 2.2
*/
- /*public*/ final T fromJson(Reader in) throws IOException {
+ public final T fromJson(Reader in) throws IOException {
JsonReader reader = new JsonReader(in);
reader.setLenient(true); // TODO: non-lenient?
return read(reader);
@@ -261,8 +265,9 @@ public abstract class TypeAdapter {
* JsonReader} and call {@link #read(JsonReader)} for lenient reading.
*
* @return the converted Java object. May be null.
+ * @since 2.2
*/
- /*public*/ final T fromJson(String json) throws IOException {
+ public final T fromJson(String json) throws IOException {
return fromJson(new StringReader(json));
}
@@ -270,8 +275,9 @@ public abstract class TypeAdapter {
* Converts {@code jsonTree} to a Java object.
*
* @param jsonTree the Java object to convert. May be {@link JsonNull}.
+ * @since 2.2
*/
- /*public*/ final T fromJsonTree(JsonElement jsonTree) {
+ public final T fromJsonTree(JsonElement jsonTree) {
try {
JsonReader jsonReader = new JsonTreeReader(jsonTree);
jsonReader.setLenient(true);
diff --git a/gson/src/main/java/com/google/gson/internal/bind/MapTypeAdapterFactory.java b/gson/src/main/java/com/google/gson/internal/bind/MapTypeAdapterFactory.java
index b64c5524..ed45d51b 100644
--- a/gson/src/main/java/com/google/gson/internal/bind/MapTypeAdapterFactory.java
+++ b/gson/src/main/java/com/google/gson/internal/bind/MapTypeAdapterFactory.java
@@ -16,9 +16,14 @@
package com.google.gson.internal.bind;
+import java.io.IOException;
+import java.lang.reflect.Type;
+import java.util.ArrayList;
+import java.util.List;
+import java.util.Map;
+
import com.google.gson.Gson;
import com.google.gson.JsonElement;
-import com.google.gson.JsonIOException;
import com.google.gson.JsonPrimitive;
import com.google.gson.JsonSyntaxException;
import com.google.gson.TypeAdapter;
@@ -32,11 +37,6 @@ import com.google.gson.reflect.TypeToken;
import com.google.gson.stream.JsonReader;
import com.google.gson.stream.JsonToken;
import com.google.gson.stream.JsonWriter;
-import java.io.IOException;
-import java.lang.reflect.Type;
-import java.util.ArrayList;
-import java.util.List;
-import java.util.Map;
/**
* Adapts maps to either JSON objects or JSON arrays.
@@ -217,7 +217,7 @@ public final class MapTypeAdapterFactory implements TypeAdapterFactory {
List values = new ArrayList(map.size());
for (Map.Entry entry : map.entrySet()) {
- JsonElement keyElement = toJsonTree(keyTypeAdapter, entry.getKey());
+ JsonElement keyElement = keyTypeAdapter.toJsonTree(entry.getKey());
keys.add(keyElement);
values.add(entry.getValue());
hasComplexKeys |= keyElement.isJsonArray() || keyElement.isJsonObject();
@@ -262,16 +262,4 @@ public final class MapTypeAdapterFactory implements TypeAdapterFactory {
}
}
}
-
- // TODO: remove this when TypeAdapter.toJsonTree() is public
- private static JsonElement toJsonTree(TypeAdapter typeAdapter, T value) {
- try {
- JsonTreeWriter jsonWriter = new JsonTreeWriter();
- jsonWriter.setLenient(true);
- typeAdapter.write(jsonWriter, value);
- return jsonWriter.get();
- } catch (IOException e) {
- throw new JsonIOException(e);
- }
- }
}