Skip to content

Commit 789bb16

Browse files
committed
Add to Gson.fromJson javadoc that JSON is fully consumed
The newly added documentation deliberately does not state which exception is thrown because Gson.assertFullConsumption could throw either a JsonIOException or a JsonSyntaxException.
1 parent ab6284c commit 789bb16

File tree

1 file changed

+18
-0
lines changed

1 file changed

+18
-0
lines changed

gson/src/main/java/com/google/gson/Gson.java

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -829,6 +829,9 @@ public void toJson(JsonElement jsonElement, JsonWriter writer) throws JsonIOExce
829829
* {@link #fromJson(String, Type)}. If you have the JSON in a {@link Reader} instead of
830830
* a String, use {@link #fromJson(Reader, Class)} instead.
831831
*
832+
* <p>This method tries to fully consume the JSON and throws an exception in case that is not
833+
* possible. Use {@link #fromJson(JsonReader, Class)} if this behavior is not desired.
834+
*
832835
* @param <T> the type of the desired object
833836
* @param json the string from which the object is to be deserialized
834837
* @param classOfT the class of T
@@ -857,6 +860,9 @@ public <T> T fromJson(String json, Class<T> classOfT) throws JsonSyntaxException
857860
* <p>If you are creating the {@code Type} from a {@link TypeToken}, prefer using
858861
* {@link #fromJson(String, TypeToken)} instead since its return type is based on the
859862
* {@code TypeToken} and is therefore more type-safe.
863+
*
864+
* <p>This method tries to fully consume the JSON and throws an exception in case that is not
865+
* possible. Use {@link #fromJson(JsonReader, Type)} if this behavior is not desired.
860866
*
861867
* @param <T> the type of the desired object
862868
* @param json the string from which the object is to be deserialized
@@ -885,6 +891,9 @@ public <T> T fromJson(String json, Type typeOfT) throws JsonSyntaxException {
885891
* {@link #fromJson(String, Class)} instead. If you have the JSON in a {@link Reader} instead of
886892
* a String, use {@link #fromJson(Reader, TypeToken)} instead.
887893
*
894+
* <p>This method tries to fully consume the JSON and throws an exception in case that is not
895+
* possible. Use {@link #fromJson(JsonReader, TypeToken)} if this behavior is not desired.
896+
*
888897
* @param <T> the type of the desired object
889898
* @param json the string from which the object is to be deserialized
890899
* @param typeOfT The specific genericized type of src. You should create an anonymous subclass of
@@ -914,6 +923,9 @@ public <T> T fromJson(String json, TypeToken<T> typeOfT) throws JsonSyntaxExcept
914923
* object itself should not be a generic type. For the cases when the object is of generic type,
915924
* invoke {@link #fromJson(Reader, Type)}. If you have the JSON in a String form instead of a
916925
* {@link Reader}, use {@link #fromJson(String, Class)} instead.
926+
*
927+
* <p>This method tries to fully consume the JSON and throws an exception in case that is not
928+
* possible. Use {@link #fromJson(JsonReader, Class)} if this behavior is not desired.
917929
*
918930
* @param <T> the type of the desired object
919931
* @param json the reader producing the JSON from which the object is to be deserialized.
@@ -945,6 +957,9 @@ public <T> T fromJson(Reader json, Class<T> classOfT) throws JsonSyntaxException
945957
* <p>If you are creating the {@code Type} from a {@link TypeToken}, prefer using
946958
* {@link #fromJson(Reader, TypeToken)} instead since its return type is based on the
947959
* {@code TypeToken} and is therefore more type-safe.
960+
*
961+
* <p>This method tries to fully consume the JSON and throws an exception in case that is not
962+
* possible. Use {@link #fromJson(JsonReader, Type)} if this behavior is not desired.
948963
*
949964
* @param <T> the type of the desired object
950965
* @param json the reader producing JSON from which the object is to be deserialized
@@ -971,6 +986,9 @@ public <T> T fromJson(Reader json, Type typeOfT) throws JsonIOException, JsonSyn
971986
* specified type. This method is useful if the specified object is a generic type. For
972987
* non-generic objects, use {@link #fromJson(Reader, Class)} instead. If you have the JSON in a
973988
* String form instead of a {@link Reader}, use {@link #fromJson(String, TypeToken)} instead.
989+
*
990+
* <p>This method tries to fully consume the JSON and throws an exception in case that is not
991+
* possible. Use {@link #fromJson(JsonReader, TypeToken)} if this behavior is not desired.
974992
*
975993
* @param <T> the type of the desired object
976994
* @param json the reader producing JSON from which the object is to be deserialized

0 commit comments

Comments
 (0)