diff --git a/gson/docs/javadocs/allclasses-frame.html b/gson/docs/javadocs/allclasses-frame.html new file mode 100644 index 00000000..98cf2b2b --- /dev/null +++ b/gson/docs/javadocs/allclasses-frame.html @@ -0,0 +1,92 @@ + + + +
+ + +ExclusionStrategy
+ +Expose + +FieldAttributes + +FieldNamingPolicy + +FieldNamingStrategy + +Gson + +GsonBuilder + +InstanceCreator + +JsonArray + +JsonDeserializationContext + +JsonDeserializer + +JsonElement + +JsonIOException + +JsonNull + +JsonObject + +JsonParseException + +JsonParser + +JsonPrimitive + +JsonReader + +JsonSerializationContext + +JsonSerializer + +JsonStreamParser + +JsonSyntaxException + +JsonToken + +JsonWriter + +LongSerializationPolicy + +MalformedJsonException + +SerializedName + +Since + +TypeToken + +Until + + |
+
ExclusionStrategy
+ +Expose + +FieldAttributes + +FieldNamingPolicy + +FieldNamingStrategy + +Gson + +GsonBuilder + +InstanceCreator + +JsonArray + +JsonDeserializationContext + +JsonDeserializer + +JsonElement + +JsonIOException + +JsonNull + +JsonObject + +JsonParseException + +JsonParser + +JsonPrimitive + +JsonReader + +JsonSerializationContext + +JsonSerializer + +JsonStreamParser + +JsonSyntaxException + +JsonToken + +JsonWriter + +LongSerializationPolicy + +MalformedJsonException + +SerializedName + +Since + +TypeToken + +Until + + |
+
+
+
|
++ + | +|||||||||
+ PREV CLASS + NEXT CLASS | ++ FRAMES + NO FRAMES + + + + + | +|||||||||
+ SUMMARY: NESTED | FIELD | CONSTR | METHOD | ++DETAIL: FIELD | CONSTR | METHOD | +
public interface ExclusionStrategy
+A strategy (or policy) definition that is used to decide whether or not a field or top-level
+ class should be serialized or deserialized as part of the JSON output/input. For serialization,
+ if the shouldSkipClass(Class)
method returns false then that class or field type
+ will not be part of the JSON output. For deserialization, if shouldSkipClass(Class)
+ returns false, then it will not be set as part of the Java object structure.
+
+
The following are a few examples that shows how you can use this exclusion mechanism. + +
Exclude fields and objects based on a particular class type: +
+ private static class SpecificClassExclusionStrategy implements ExclusionStrategy { + private final Class<?> excludedThisClass; + + public SpecificClassExclusionStrategy(Class<?> excludedThisClass) { + this.excludedThisClass = excludedThisClass; + } + + public boolean shouldSkipClass(Class<?> clazz) { + return excludedThisClass.equals(clazz); + } + + public boolean shouldSkipField(FieldAttributes f) { + return excludedThisClass.equals(f.getDeclaredClass()); + } + } ++ +
Excludes fields and objects based on a particular annotation: +
+ public @interface FooAnnotation { + // some implementation here + } + + // Excludes any field (or class) that is tagged with an "@FooAnnotation" + private static class FooAnnotationExclusionStrategy implements ExclusionStrategy { + public boolean shouldSkipClass(Class<?> clazz) { + return clazz.getAnnotation(FooAnnotation.class) != null; + } + + public boolean shouldSkipField(FieldAttributes f) { + return f.getAnnotation(FooAnnotation.class) != null; + } + } ++ +
Now if you want to configure Gson
to use a user defined exclusion strategy, then
+ the GsonBuilder
is required. The following is an example of how you can use the
+ GsonBuilder
to configure Gson to use one of the above sample:
+
+ ExclusionStrategy excludeStrings = new UserDefinedExclusionStrategy(String.class); + Gson gson = new GsonBuilder() + .setExclusionStrategies(excludeStrings) + .create(); ++
+ +
+
GsonBuilder.setExclusionStrategies(ExclusionStrategy...)
+Method Summary | +|
---|---|
+ boolean |
+shouldSkipClass(Class<?> clazz)
+
++ |
+
+ boolean |
+shouldSkipField(FieldAttributes f)
+
++ |
+
+Method Detail | +
---|
+boolean shouldSkipField(FieldAttributes f)+
f
- the field object that is under test
++boolean shouldSkipClass(Class<?> clazz)+
clazz
- the class object that is under test
+
+
+
|
++ + | +|||||||||
+ PREV CLASS + NEXT CLASS | ++ FRAMES + NO FRAMES + + + + + | +|||||||||
+ SUMMARY: NESTED | FIELD | CONSTR | METHOD | ++DETAIL: FIELD | CONSTR | METHOD | +
+
+
|
++ + | +|||||||||
+ PREV CLASS + NEXT CLASS | ++ FRAMES + NO FRAMES + + + + + | +|||||||||
+ SUMMARY: NESTED | FIELD | CONSTR | METHOD | ++DETAIL: FIELD | CONSTR | METHOD | +
+java.lang.Object + com.google.gson.FieldAttributes ++
public final class FieldAttributes
+A data object that stores attributes of a field. + +
This class is immutable; therefore, it can be safely shared across threads. +
+ +
+
+Method Summary | +||
---|---|---|
+
+ |
+getAnnotation(Class<T> annotation)
+
++ Return the T annotation object from this field if it exist; otherwise returns
+ null . |
+|
+ Collection<Annotation> |
+getAnnotations()
+
++ Return the annotations that are present on this field. |
+|
+ Class<?> |
+getDeclaredClass()
+
++ Returns the Class<?> object that was declared for this field. |
+|
+ Type |
+getDeclaredType()
+
++ For example, assume the following class definition: + + public class Foo { + private String bar; + private List<String> red; + } + + Type listParmeterizedType = new TypeToken |
+|
+ Class<?> |
+getDeclaringClass()
+
++ |
+|
+ String |
+getName()
+
++ |
+|
+ boolean |
+hasModifier(int modifier)
+
++ Returns true if the field is defined with the modifier . |
+
Methods inherited from class java.lang.Object | +
---|
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
+
+Method Detail | +
---|
+public Class<?> getDeclaringClass()+
+public String getName()+
+public Type getDeclaredType()+
For example, assume the following class definition: +
+ public class Foo { + private String bar; + private List<String> red; + } + + Type listParmeterizedType = new TypeToken+ +>() {}.getType(); +
This method would return String.class
for the bar
field and
+ listParameterizedType
for the red
field.
+
+
+public Class<?> getDeclaredClass()+
Class<?>
object that was declared for this field.
+
+ For example, assume the following class definition: +
+ public class Foo { + private String bar; + private List<String> red; + } ++ +
This method would return String.class
for the bar
field and
+ List.class
for the red
field.
+
+
+public <T extends Annotation> T getAnnotation(Class<T> annotation)+
T
annotation object from this field if it exist; otherwise returns
+ null
.
++
annotation
- the class of the annotation that will be retrieved
+null
+public Collection<Annotation> getAnnotations()+
+
+public boolean hasModifier(int modifier)+
true
if the field is defined with the modifier
.
+
+ This method is meant to be called as: +
+ boolean hasPublicModifier = fieldAttribute.hasModifier(java.lang.reflect.Modifier.PUBLIC); ++
+
Modifier
+
+
|
++ + | +|||||||||
+ PREV CLASS + NEXT CLASS | ++ FRAMES + NO FRAMES + + + + + | +|||||||||
+ SUMMARY: NESTED | FIELD | CONSTR | METHOD | ++DETAIL: FIELD | CONSTR | METHOD | +
+
+
|
++ + | +|||||||||
+ PREV CLASS + NEXT CLASS | ++ FRAMES + NO FRAMES + + + + + | +|||||||||
+ SUMMARY: NESTED | ENUM CONSTANTS | FIELD | METHOD | ++DETAIL: ENUM CONSTANTS | FIELD | METHOD | +
+java.lang.Object + java.lang.Enum<FieldNamingPolicy> + com.google.gson.FieldNamingPolicy ++
public enum FieldNamingPolicy
+An enumeration that defines a few standard naming conventions for JSON field names.
+ This enumeration should be used in conjunction with GsonBuilder
+ to configure a Gson
instance to properly translate Java field
+ names into the desired JSON field names.
+
+ +
+
+Enum Constant Summary | +|
---|---|
LOWER_CASE_WITH_DASHES
+
++ Using this naming policy with Gson will modify the Java Field name from its camel cased + form to a lower case field name where each word is separated by a dash (-). |
+|
LOWER_CASE_WITH_UNDERSCORES
+
++ Using this naming policy with Gson will modify the Java Field name from its camel cased + form to a lower case field name where each word is separated by an underscore (_). |
+|
UPPER_CAMEL_CASE
+
++ Using this naming policy with Gson will ensure that the first "letter" of the Java + field name is capitalized when serialized to its JSON form. |
+|
UPPER_CAMEL_CASE_WITH_SPACES
+
++ Using this naming policy with Gson will ensure that the first "letter" of the Java + field name is capitalized when serialized to its JSON form and the words will be + separated by a space. |
+
+Method Summary | +|
---|---|
+static FieldNamingPolicy |
+valueOf(String name)
+
++ Returns the enum constant of this type with the specified name. |
+
+static FieldNamingPolicy[] |
+values()
+
++ Returns an array containing the constants of this enum type, in +the order they are declared. |
+
Methods inherited from class java.lang.Enum | +
---|
compareTo, equals, getDeclaringClass, hashCode, name, ordinal, toString, valueOf |
+
Methods inherited from class java.lang.Object | +
---|
getClass, notify, notifyAll, wait, wait, wait |
+
+Enum Constant Detail | +
---|
+public static final FieldNamingPolicy UPPER_CAMEL_CASE+
Here's a few examples of the form "Java Field Name" ---> "JSON Field Name":
++
+public static final FieldNamingPolicy UPPER_CAMEL_CASE_WITH_SPACES+
Here's a few examples of the form "Java Field Name" ---> "JSON Field Name":
++
+public static final FieldNamingPolicy LOWER_CASE_WITH_UNDERSCORES+
Here's a few examples of the form "Java Field Name" ---> "JSON Field Name":
++
+public static final FieldNamingPolicy LOWER_CASE_WITH_DASHES+
Here's a few examples of the form "Java Field Name" ---> "JSON Field Name":
+myobject['my-field']
. Accessing it as an object field
+ myobject.my-field
will result in an unintended javascript expression.
++
+Method Detail | +
---|
+public static FieldNamingPolicy[] values()+
+for (FieldNamingPolicy c : FieldNamingPolicy.values()) + System.out.println(c); ++
+
+public static FieldNamingPolicy valueOf(String name)+
+
name
- the name of the enum constant to be returned.
+IllegalArgumentException
- if this enum type has no constant
+with the specified name
+NullPointerException
- if the argument is null
+
+
|
++ + | +|||||||||
+ PREV CLASS + NEXT CLASS | ++ FRAMES + NO FRAMES + + + + + | +|||||||||
+ SUMMARY: NESTED | ENUM CONSTANTS | FIELD | METHOD | ++DETAIL: ENUM CONSTANTS | FIELD | METHOD | +
+
+
|
++ + | +|||||||||
+ PREV CLASS + NEXT CLASS | ++ FRAMES + NO FRAMES + + + + + | +|||||||||
+ SUMMARY: NESTED | FIELD | CONSTR | METHOD | ++DETAIL: FIELD | CONSTR | METHOD | +
public interface FieldNamingStrategy
+A mechanism for providing custom field naming in Gson. This allows the client code to translate + field names into a particular convention that is not supported as a normal Java field + declaration rules. For example, Java does not support "-" characters in a field name. +
+ +
+
+Method Summary | +|
---|---|
+ String |
+translateName(Field f)
+
++ Translates the field name into its JSON field name representation. |
+
+Method Detail | +
---|
+String translateName(Field f)+
+
f
- the field object that we are translating
+
+
+
|
++ + | +|||||||||
+ PREV CLASS + NEXT CLASS | ++ FRAMES + NO FRAMES + + + + + | +|||||||||
+ SUMMARY: NESTED | FIELD | CONSTR | METHOD | ++DETAIL: FIELD | CONSTR | METHOD | +
+
+
|
++ + | +|||||||||
+ PREV CLASS + NEXT CLASS | ++ FRAMES + NO FRAMES + + + + + | +|||||||||
+ SUMMARY: NESTED | FIELD | CONSTR | METHOD | ++DETAIL: FIELD | CONSTR | METHOD | +
+java.lang.Object + com.google.gson.Gson ++
public final class Gson
+This is the main class for using Gson. Gson is typically used by first constructing a
+ Gson instance and then invoking toJson(Object)
or fromJson(String, Class)
+ methods on it.
+
+
You can create a Gson instance by invoking new Gson()
if the default configuration
+ is all you need. You can also use GsonBuilder
to build a Gson instance with various
+ configuration options such as versioning support, pretty printing, custom
+ JsonSerializer
s, JsonDeserializer
s, and InstanceCreator
s.
Here is an example of how Gson is used for a simple Class: + +
+ Gson gson = new Gson(); // Or use new GsonBuilder().create(); + MyType target = new MyType(); + String json = gson.toJson(target); // serializes target to Json + MyType target2 = gson.fromJson(json, MyType.class); // deserializes json into target2 ++ +
If the object that your are serializing/deserializing is a ParameterizedType
+ (i.e. contains at least one type parameter and may be an array) then you must use the
+ toJson(Object, Type)
or fromJson(String, Type)
method. Here is an
+ example for serializing and deserialing a ParameterizedType
:
+
+
+ Type listType = new TypeToken<List<String>>() {}.getType(); + List<String> target = new LinkedList<String>(); + target.add("blah"); + + Gson gson = new Gson(); + String json = gson.toJson(target, listType); + List<String> target2 = gson.fromJson(json, listType); ++ +
See the Gson User Guide + for a more complete set of examples.
++ +
+
TypeToken
+Constructor Summary | +|
---|---|
Gson()
+
++ Constructs a Gson object with default configuration. |
+
+Method Summary | +||
---|---|---|
+
+ |
+fromJson(JsonElement json,
+ Class<T> classOfT)
+
++ This method deserializes the Json read from the specified parse tree into an object of the + specified type. |
+|
+
+ |
+fromJson(JsonElement json,
+ Type typeOfT)
+
++ This method deserializes the Json read from the specified parse tree into an object of the + specified type. |
+|
+
+ |
+fromJson(JsonReader reader,
+ Type typeOfT)
+
++ Reads the next JSON value from reader and convert it to an object
+ of type typeOfT . |
+|
+
+ |
+fromJson(Reader json,
+ Class<T> classOfT)
+
++ This method deserializes the Json read from the specified reader into an object of the + specified class. |
+|
+
+ |
+fromJson(Reader json,
+ Type typeOfT)
+
++ This method deserializes the Json read from the specified reader into an object of the + specified type. |
+|
+
+ |
+fromJson(String json,
+ Class<T> classOfT)
+
++ This method deserializes the specified Json into an object of the specified class. |
+|
+
+ |
+fromJson(String json,
+ Type typeOfT)
+
++ This method deserializes the specified Json into an object of the specified type. |
+|
+ String |
+toJson(JsonElement jsonElement)
+
++ Converts a tree of JsonElement s into its equivalent JSON representation. |
+|
+ void |
+toJson(JsonElement jsonElement,
+ Appendable writer)
+
++ Writes out the equivalent JSON for a tree of JsonElement s. |
+|
+ void |
+toJson(JsonElement jsonElement,
+ JsonWriter writer)
+
++ Writes the JSON for jsonElement to writer . |
+|
+ String |
+toJson(Object src)
+
++ This method serializes the specified object into its equivalent Json representation. |
+|
+ void |
+toJson(Object src,
+ Appendable writer)
+
++ This method serializes the specified object into its equivalent Json representation. |
+|
+ String |
+toJson(Object src,
+ Type typeOfSrc)
+
++ This method serializes the specified object, including those of generic types, into its + equivalent Json representation. |
+|
+ void |
+toJson(Object src,
+ Type typeOfSrc,
+ Appendable writer)
+
++ This method serializes the specified object, including those of generic types, into its + equivalent Json representation. |
+|
+ void |
+toJson(Object src,
+ Type typeOfSrc,
+ JsonWriter writer)
+
++ Writes the JSON representation of src of type typeOfSrc to
+ writer . |
+|
+ JsonElement |
+toJsonTree(Object src)
+
++ This method serializes the specified object into its equivalent representation as a tree of + JsonElement s. |
+|
+ JsonElement |
+toJsonTree(Object src,
+ Type typeOfSrc)
+
++ This method serializes the specified object, including those of generic types, into its + equivalent representation as a tree of JsonElement s. |
+|
+ String |
+toString()
+
++ |
+
Methods inherited from class java.lang.Object | +
---|
equals, getClass, hashCode, notify, notifyAll, wait, wait, wait |
+
+Constructor Detail | +
---|
+public Gson()+
toJson
methods is in compact representation. This
+ means that all the unneeded white-space is removed. You can change this behavior with
+ GsonBuilder.setPrettyPrinting()
. GsonBuilder.serializeNulls()
.Map
,
+ URL
, URI
, Locale
, Date
,
+ BigDecimal
, and BigInteger
classes. If you would prefer
+ to change the default representation, you can do so by registering a type adapter through
+ GsonBuilder.registerTypeAdapter(Type, Object)
. DateFormat.DEFAULT
. This format
+ ignores the millisecond portion of the date during serialization. You can change
+ this by invoking GsonBuilder.setDateFormat(int)
or
+ GsonBuilder.setDateFormat(String)
. Expose
annotation.
+ You can enable Gson to serialize/deserialize only those fields marked with this annotation
+ through GsonBuilder.excludeFieldsWithoutExposeAnnotation()
. Since
annotation. You
+ can enable Gson to use this annotation through GsonBuilder.setVersion(double)
.versionNumber
will be output as "versionNumber@quot;
in
+ Json. The same rules are applied for mapping incoming Json to the Java classes. You can
+ change this policy through GsonBuilder.setFieldNamingPolicy(FieldNamingPolicy)
.transient
or static
fields from
+ consideration for serialization and deserialization. You can change this behavior through
+ GsonBuilder.excludeFieldsWithModifiers(int...)
.+
+Method Detail | +
---|
+public JsonElement toJsonTree(Object src)+
JsonElement
s. This method should be used when the specified object is not a generic
+ type. This method uses Object.getClass()
to get the type for the specified object, but
+ the getClass()
loses the generic type information because of the Type Erasure feature
+ of Java. Note that this method works fine if the any of the object fields are of generic type,
+ just the object itself should not be of a generic type. If the object is of generic type, use
+ toJsonTree(Object, Type)
instead.
++
src
- the object for which Json representation is to be created setting for Gson
+src
.+public JsonElement toJsonTree(Object src, + Type typeOfSrc)+
JsonElement
s. This method must be used if the
+ specified object is a generic type. For non-generic objects, use toJsonTree(Object)
+ instead.
++
src
- the object for which JSON representation is to be createdtypeOfSrc
- The specific genericized type of src. You can obtain
+ this type by using the TypeToken
class. For example,
+ to get the type for Collection<Foo>
, you should use:
+ + Type typeOfSrc = new TypeToken<Collection<Foo>>(){}.getType(); ++
src
+public String toJson(Object src)+
Object.getClass()
to get the type for the specified object, but the
+ getClass()
loses the generic type information because of the Type Erasure feature
+ of Java. Note that this method works fine if the any of the object fields are of generic type,
+ just the object itself should not be of a generic type. If the object is of generic type, use
+ toJson(Object, Type)
instead. If you want to write out the object to a
+ Writer
, use toJson(Object, Appendable)
instead.
++
src
- the object for which Json representation is to be created setting for Gson
+src
.+public String toJson(Object src, + Type typeOfSrc)+
toJson(Object)
instead. If you want to write out
+ the object to a Appendable
, use toJson(Object, Type, Appendable)
instead.
++
src
- the object for which JSON representation is to be createdtypeOfSrc
- The specific genericized type of src. You can obtain
+ this type by using the TypeToken
class. For example,
+ to get the type for Collection<Foo>
, you should use:
+ + Type typeOfSrc = new TypeToken<Collection<Foo>>(){}.getType(); ++
src
+public void toJson(Object src, + Appendable writer) + throws JsonIOException+
Object.getClass()
to get the type for the specified object, but the
+ getClass()
loses the generic type information because of the Type Erasure feature
+ of Java. Note that this method works fine if the any of the object fields are of generic type,
+ just the object itself should not be of a generic type. If the object is of generic type, use
+ toJson(Object, Type, Appendable)
instead.
++
src
- the object for which Json representation is to be created setting for Gsonwriter
- Writer to which the Json representation needs to be written
+JsonIOException
- if there was a problem writing to the writer+public void toJson(Object src, + Type typeOfSrc, + Appendable writer) + throws JsonIOException+
toJson(Object, Appendable)
instead.
++
src
- the object for which JSON representation is to be createdtypeOfSrc
- The specific genericized type of src. You can obtain
+ this type by using the TypeToken
class. For example,
+ to get the type for Collection<Foo>
, you should use:
+ + Type typeOfSrc = new TypeToken<Collection<Foo>>(){}.getType(); +
writer
- Writer to which the Json representation of src needs to be written.
+JsonIOException
- if there was a problem writing to the writer+public void toJson(Object src, + Type typeOfSrc, + JsonWriter writer) + throws JsonIOException+
src
of type typeOfSrc
to
+ writer
.
++
JsonIOException
- if there was a problem writing to the writer+public String toJson(JsonElement jsonElement)+
JsonElement
s into its equivalent JSON representation.
++
jsonElement
- root of a tree of JsonElement
s
++public void toJson(JsonElement jsonElement, + Appendable writer) + throws JsonIOException+
JsonElement
s.
++
jsonElement
- root of a tree of JsonElement
swriter
- Writer to which the Json representation needs to be written
+JsonIOException
- if there was a problem writing to the writer+public void toJson(JsonElement jsonElement, + JsonWriter writer) + throws JsonIOException+
jsonElement
to writer
.
++
JsonIOException
- if there was a problem writing to the writer+public <T> T fromJson(String json, + Class<T> classOfT) + throws JsonSyntaxException+
fromJson(String, Type)
. If you have the Json in a Reader
instead of
+ a String, use fromJson(Reader, Class)
instead.
++
T
- the type of the desired objectjson
- the string from which the object is to be deserializedclassOfT
- the class of T
+JsonSyntaxException
- if json is not a valid representation for an object of type
+ classOfT+public <T> T fromJson(String json, + Type typeOfT) + throws JsonSyntaxException+
fromJson(String, Class)
instead. If you have the Json in a Reader
instead of
+ a String, use fromJson(Reader, Type)
instead.
++
T
- the type of the desired objectjson
- the string from which the object is to be deserializedtypeOfT
- The specific genericized type of src. You can obtain this type by using the
+ TypeToken
class. For example, to get the type for
+ Collection<Foo>
, you should use:
+ + Type typeOfT = new TypeToken<Collection<Foo>>(){}.getType(); ++
JsonParseException
- if json is not a valid representation for an object of type typeOfT
+JsonSyntaxException
- if json is not a valid representation for an object of type+public <T> T fromJson(Reader json, + Class<T> classOfT) + throws JsonSyntaxException, + JsonIOException+
fromJson(Reader, Type)
. If you have the Json in a String form instead of a
+ Reader
, use fromJson(String, Class)
instead.
++
T
- the type of the desired objectjson
- the reader producing the Json from which the object is to be deserialized.classOfT
- the class of T
+JsonIOException
- if there was a problem reading from the Reader
+JsonSyntaxException
- if json is not a valid representation for an object of type+public <T> T fromJson(Reader json, + Type typeOfT) + throws JsonIOException, + JsonSyntaxException+
fromJson(Reader, Class)
instead. If you have the Json in a
+ String form instead of a Reader
, use fromJson(String, Type)
instead.
++
T
- the type of the desired objectjson
- the reader producing Json from which the object is to be deserializedtypeOfT
- The specific genericized type of src. You can obtain this type by using the
+ TypeToken
class. For example, to get the type for
+ Collection<Foo>
, you should use:
+ + Type typeOfT = new TypeToken<Collection<Foo>>(){}.getType(); ++
JsonIOException
- if there was a problem reading from the Reader
+JsonSyntaxException
- if json is not a valid representation for an object of type+public <T> T fromJson(JsonReader reader, + Type typeOfT) + throws JsonIOException, + JsonSyntaxException+
reader
and convert it to an object
+ of type typeOfT
.
+ Since Type is not parameterized by T, this method is type unsafe and should be used carefully
++
JsonIOException
- if there was a problem writing to the Reader
+JsonSyntaxException
- if json is not a valid representation for an object of type+public <T> T fromJson(JsonElement json, + Class<T> classOfT) + throws JsonSyntaxException+
fromJson(JsonElement, Type)
.
++
T
- the type of the desired objectjson
- the root of the parse tree of JsonElement
s from which the object is to
+ be deserializedclassOfT
- The class of T
+JsonSyntaxException
- if json is not a valid representation for an object of type typeOfT+public <T> T fromJson(JsonElement json, + Type typeOfT) + throws JsonSyntaxException+
fromJson(JsonElement, Class)
instead.
++
T
- the type of the desired objectjson
- the root of the parse tree of JsonElement
s from which the object is to
+ be deserializedtypeOfT
- The specific genericized type of src. You can obtain this type by using the
+ TypeToken
class. For example, to get the type for
+ Collection<Foo>
, you should use:
+ + Type typeOfT = new TypeToken<Collection<Foo>>(){}.getType(); ++
JsonSyntaxException
- if json is not a valid representation for an object of type typeOfT+public String toString()+
toString
in class Object
+
+
|
++ + | +|||||||||
+ PREV CLASS + NEXT CLASS | ++ FRAMES + NO FRAMES + + + + + | +|||||||||
+ SUMMARY: NESTED | FIELD | CONSTR | METHOD | ++DETAIL: FIELD | CONSTR | METHOD | +
+
+
|
++ + | +|||||||||
+ PREV CLASS + NEXT CLASS | ++ FRAMES + NO FRAMES + + + + + | +|||||||||
+ SUMMARY: NESTED | FIELD | CONSTR | METHOD | ++DETAIL: FIELD | CONSTR | METHOD | +
+java.lang.Object + com.google.gson.GsonBuilder ++
public final class GsonBuilder
+
Use this builder to construct a Gson
instance when you need to set configuration
+ options other than the default. For Gson
with default configuration, it is simpler to
+ use new Gson()
. GsonBuilder
is best used by creating it, and then invoking its
+ various configuration methods, and finally calling create.
The following is an example shows how to use the GsonBuilder
to construct a Gson
+ instance:
+
+
+ Gson gson = new GsonBuilder() + .registerTypeAdapter(Id.class, new IdTypeAdapter()) + .serializeNulls() + .setDateFormat(DateFormat.LONG) + .setFieldNamingPolicy(FieldNamingPolicy.UPPER_CAMEL_CASE) + .setPrettyPrinting() + .setVersion(1.0) + .create(); ++ +
NOTE: the order of invocation of configuration methods does not matter.
++ +
+
+Constructor Summary | +|
---|---|
GsonBuilder()
+
++ Creates a GsonBuilder instance that can be used to build Gson with various configuration + settings. |
+
+Method Summary | +|
---|---|
+ Gson |
+create()
+
++ Creates a Gson instance based on the current configuration. |
+
+ GsonBuilder |
+disableHtmlEscaping()
+
++ By default, Gson escapes HTML characters such as < > etc. |
+
+ GsonBuilder |
+disableInnerClassSerialization()
+
++ Configures Gson to exclude inner classes during serialization. |
+
+ GsonBuilder |
+excludeFieldsWithModifiers(int... modifiers)
+
++ Configures Gson to excludes all class fields that have the specified modifiers. |
+
+ GsonBuilder |
+excludeFieldsWithoutExposeAnnotation()
+
++ Configures Gson to exclude all fields from consideration for serialization or deserialization + that do not have the Expose annotation. |
+
+ GsonBuilder |
+generateNonExecutableJson()
+
++ Makes the output JSON non-executable in Javascript by prefixing the generated JSON with some + special text. |
+
+ GsonBuilder |
+registerTypeAdapter(Type type,
+ Object typeAdapter)
+
++ Configures Gson for custom serialization or deserialization. |
+
+ GsonBuilder |
+serializeNulls()
+
++ Configure Gson to serialize null fields. |
+
+ GsonBuilder |
+serializeSpecialFloatingPointValues()
+
++ Section 2.4 of JSON specification disallows + special double values (NaN, Infinity, -Infinity). |
+
+ GsonBuilder |
+setDateFormat(int style)
+
++ Configures Gson to to serialize Date objects according to the style value provided. |
+
+ GsonBuilder |
+setDateFormat(int dateStyle,
+ int timeStyle)
+
++ Configures Gson to to serialize Date objects according to the style value provided. |
+
+ GsonBuilder |
+setDateFormat(String pattern)
+
++ Configures Gson to serialize Date objects according to the pattern provided. |
+
+ GsonBuilder |
+setExclusionStrategies(ExclusionStrategy... strategies)
+
++ Configures Gson to apply a set of exclusion strategies during both serialization and + deserialization. |
+
+ GsonBuilder |
+setFieldNamingPolicy(FieldNamingPolicy namingConvention)
+
++ Configures Gson to apply a specific naming policy to an object's field during serialization + and deserialization. |
+
+ GsonBuilder |
+setFieldNamingStrategy(FieldNamingStrategy fieldNamingStrategy)
+
++ Configures Gson to apply a specific naming policy strategy to an object's field during + serialization and deserialization. |
+
+ GsonBuilder |
+setLongSerializationPolicy(LongSerializationPolicy serializationPolicy)
+
++ Configures Gson to apply a specific serialization policy for Long and long
+ objects. |
+
+ GsonBuilder |
+setPrettyPrinting()
+
++ Configures Gson to output Json that fits in a page for pretty printing. |
+
+ GsonBuilder |
+setVersion(double ignoreVersionsAfter)
+
++ Configures Gson to enable versioning support. |
+
Methods inherited from class java.lang.Object | +
---|
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
+
+Constructor Detail | +
---|
+public GsonBuilder()+
create()
.
++
+Method Detail | +
---|
+public GsonBuilder setVersion(double ignoreVersionsAfter)+
+
ignoreVersionsAfter
- any field or type marked with a version higher than this value
+ are ignored during serialization or deserialization.
+GsonBuilder
object to fulfill the "Builder" pattern+public GsonBuilder excludeFieldsWithModifiers(int... modifiers)+
+
modifiers
- the field modifiers. You must use the modifiers specified in the
+ Modifier
class. For example,
+ Modifier.TRANSIENT
,
+ Modifier.STATIC
.
+GsonBuilder
object to fulfill the "Builder" pattern+public GsonBuilder generateNonExecutableJson()+
+
GsonBuilder
object to fulfill the "Builder" pattern+public GsonBuilder excludeFieldsWithoutExposeAnnotation()+
Expose
annotation.
++
GsonBuilder
object to fulfill the "Builder" pattern+public GsonBuilder serializeNulls()+
+
GsonBuilder
object to fulfill the "Builder" pattern+public GsonBuilder disableInnerClassSerialization()+
+
GsonBuilder
object to fulfill the "Builder" pattern+public GsonBuilder setLongSerializationPolicy(LongSerializationPolicy serializationPolicy)+
Long
and long
+ objects.
++
serializationPolicy
- the particular policy to use for serializing longs.
+GsonBuilder
object to fulfill the "Builder" pattern+public GsonBuilder setFieldNamingPolicy(FieldNamingPolicy namingConvention)+
+
namingConvention
- the JSON field naming convention to use for serialization and
+ deserialization.
+GsonBuilder
object to fulfill the "Builder" pattern+public GsonBuilder setFieldNamingStrategy(FieldNamingStrategy fieldNamingStrategy)+
+
fieldNamingStrategy
- the actual naming strategy to apply to the fields
+GsonBuilder
object to fulfill the "Builder" pattern+public GsonBuilder setExclusionStrategies(ExclusionStrategy... strategies)+
strategies
will be applied as a disjunction rule.
+ This means that if one of the strategies
suggests that a field (or class) should be
+ skipped then that field (or object) is skipped during serializaiton/deserialization.
++
strategies
- the set of strategy object to apply during object (de)serialization.
+GsonBuilder
object to fulfill the "Builder" pattern+public GsonBuilder setPrettyPrinting()+
+
GsonBuilder
object to fulfill the "Builder" pattern+public GsonBuilder disableHtmlEscaping()+
+
GsonBuilder
object to fulfill the "Builder" pattern+public GsonBuilder setDateFormat(String pattern)+
Date
objects according to the pattern provided. You can
+ call this method or setDateFormat(int)
multiple times, but only the last invocation
+ will be used to decide the serialization format.
+
+ Note that this pattern must abide by the convention provided by SimpleDateFormat
+ class. See the documentation in SimpleDateFormat
for more information on
+ valid date and time patterns.
+
pattern
- the pattern that dates will be serialized/deserialized to/from
+GsonBuilder
object to fulfill the "Builder" pattern+public GsonBuilder setDateFormat(int style)+
Date
objects according to the style value provided.
+ You can call this method or setDateFormat(String)
multiple times, but only the last
+ invocation will be used to decide the serialization format.
+
+ Note that this style value should be one of the predefined constants in the
+ DateFormat
class. See the documentation in DateFormat
for more
+ information on the valid style constants.
+
style
- the predefined date style that date objects will be serialized/deserialized
+ to/from
+GsonBuilder
object to fulfill the "Builder" pattern+public GsonBuilder setDateFormat(int dateStyle, + int timeStyle)+
Date
objects according to the style value provided.
+ You can call this method or setDateFormat(String)
multiple times, but only the last
+ invocation will be used to decide the serialization format.
+
+ Note that this style value should be one of the predefined constants in the
+ DateFormat
class. See the documentation in DateFormat
for more
+ information on the valid style constants.
+
dateStyle
- the predefined date style that date objects will be serialized/deserialized
+ to/fromtimeStyle
- the predefined style for the time portion of the date objects
+GsonBuilder
object to fulfill the "Builder" pattern+public GsonBuilder registerTypeAdapter(Type type, + Object typeAdapter)+
InstanceCreator
, JsonSerializer
, and a
+ JsonDeserializer
. It is best used when a single object typeAdapter
implements
+ all the required interfaces for custom serialization with Gson. If an instance creator,
+ serializer or deserializer was previously registered for the specified type
, it is
+ overwritten.
++
type
- the type definition for the type adapter being registeredtypeAdapter
- This object must implement at least one of the InstanceCreator
,
+ JsonSerializer
, and a JsonDeserializer
interfaces.
+GsonBuilder
object to fulfill the "Builder" pattern+public GsonBuilder serializeSpecialFloatingPointValues()+
Gson always accepts these special values during deserialization. However, it outputs
+ strictly compliant JSON. Hence, if it encounters a float value Float.NaN
,
+ Float.POSITIVE_INFINITY
, Float.NEGATIVE_INFINITY
, or a double value
+ Double.NaN
, Double.POSITIVE_INFINITY
, Double.NEGATIVE_INFINITY
, it
+ will throw an IllegalArgumentException
. This method provides a way to override the
+ default behavior when you know that the JSON receiver will be able to handle these special
+ values.
+
+
GsonBuilder
object to fulfill the "Builder" pattern+public Gson create()+
Gson
instance based on the current configuration. This method is free of
+ side-effects to this GsonBuilder
instance and hence can be called multiple times.
++
+
+
|
++ + | +|||||||||
+ PREV CLASS + NEXT CLASS | ++ FRAMES + NO FRAMES + + + + + | +|||||||||
+ SUMMARY: NESTED | FIELD | CONSTR | METHOD | ++DETAIL: FIELD | CONSTR | METHOD | +
+
+
|
++ + | +|||||||||
+ PREV CLASS + NEXT CLASS | ++ FRAMES + NO FRAMES + + + + + | +|||||||||
+ SUMMARY: NESTED | FIELD | CONSTR | METHOD | ++DETAIL: FIELD | CONSTR | METHOD | +
T
- the type of object that will be created by this implementation.public interface InstanceCreator<T>
+This interface is implemented to create instances of a class that does not define a no-args
+ constructor. If you can modify the class, you should instead add a private, or public
+ no-args constructor. However, that is not possible for library classes, such as JDK classes, or
+ a third-party library that you do not have source-code of. In such cases, you should define an
+ instance creator for the class. Implementations of this interface should be registered with
+ GsonBuilder.registerTypeAdapter(Type, Object)
method before Gson will be able to use
+ them.
+
Let us look at an example where defining an InstanceCreator might be useful. The
+ Id
class defined below does not have a default no-args constructor.
+ public class Id<T> { + private final Class<T> clazz; + private final long value; + public Id(Class<T> clazz, long value) { + this.clazz = clazz; + this.value = value; + } + } ++ +
If Gson encounters an object of type Id
during deserialization, it will throw an
+ exception. The easiest way to solve this problem will be to add a (public or private) no-args
+ constructor as follows:
+ private Id() { + this(Object.class, 0L); + } ++ +
However, let us assume that the developer does not have access to the source-code of the
+ Id
class, or does not want to define a no-args constructor for it. The developer
+ can solve this problem by defining an InstanceCreator
for Id
:
+ class IdInstanceCreator implements InstanceCreator<Id> { + public Id createInstance(Type type) { + return new Id(Object.class, 0L); + } + } ++ +
Note that it does not matter what the fields of the created instance contain since Gson will
+ overwrite them with the deserialized values specified in Json. You should also ensure that a
+ new object is returned, not a common object since its fields will be overwritten.
+ The developer will need to register IdInstanceCreator
with Gson as follows:
+ Gson gson = new GsonBuilder().registerTypeAdapter(Id.class, new IdInstanceCreator()).create(); ++
+ +
+
+Method Summary | +|
---|---|
+ T |
+createInstance(Type type)
+
++ Gson invokes this call-back method during deserialization to create an instance of the + specified type. |
+
+Method Detail | +
---|
+T createInstance(Type type)+
new
to create a new instance.
++
type
- the parameterized T represented as a Type
.
+
+
+
|
++ + | +|||||||||
+ PREV CLASS + NEXT CLASS | ++ FRAMES + NO FRAMES + + + + + | +|||||||||
+ SUMMARY: NESTED | FIELD | CONSTR | METHOD | ++DETAIL: FIELD | CONSTR | METHOD | +
+
+
|
++ + | +|||||||||
+ PREV CLASS + NEXT CLASS | ++ FRAMES + NO FRAMES + + + + + | +|||||||||
+ SUMMARY: NESTED | FIELD | CONSTR | METHOD | ++DETAIL: FIELD | CONSTR | METHOD | +
+java.lang.Object + com.google.gson.JsonElement + com.google.gson.JsonArray ++
public final class JsonArray
+A class representing an array type in Json. An array is a list of JsonElement
s each of
+ which can be of a different type. This is an ordered list, meaning that the order in which
+ elements are added is preserved.
+
+ +
+
+Constructor Summary | +|
---|---|
JsonArray()
+
++ Creates an empty JsonArray. |
+
+Method Summary | +|
---|---|
+ void |
+add(JsonElement element)
+
++ Adds the specified element to self. |
+
+ void |
+addAll(JsonArray array)
+
++ Adds all the elements of the specified array to self. |
+
+ JsonElement |
+get(int i)
+
++ Returns the ith element of the array. |
+
+ BigDecimal |
+getAsBigDecimal()
+
++ convenience method to get this array as a BigDecimal if it contains a single element. |
+
+ BigInteger |
+getAsBigInteger()
+
++ convenience method to get this array as a BigInteger if it contains a single element. |
+
+ boolean |
+getAsBoolean()
+
++ convenience method to get this array as a boolean if it contains a single element. |
+
+ byte |
+getAsByte()
+
++ convenience method to get this element as a primitive byte value. |
+
+ char |
+getAsCharacter()
+
++ convenience method to get this element as a primitive character value. |
+
+ double |
+getAsDouble()
+
++ convenience method to get this array as a double if it contains a single element. |
+
+ float |
+getAsFloat()
+
++ convenience method to get this array as a float if it contains a single element. |
+
+ int |
+getAsInt()
+
++ convenience method to get this array as an integer if it contains a single element. |
+
+ long |
+getAsLong()
+
++ convenience method to get this array as a long if it contains a single element. |
+
+ Number |
+getAsNumber()
+
++ convenience method to get this array as a Number if it contains a single element. |
+
+ short |
+getAsShort()
+
++ convenience method to get this array as a primitive short if it contains a single element. |
+
+ String |
+getAsString()
+
++ convenience method to get this array as a String if it contains a single element. |
+
+ Iterator<JsonElement> |
+iterator()
+
++ Returns an iterator to navigate the elemetns of the array. |
+
+ int |
+size()
+
++ Returns the number of elements in the array. |
+
Methods inherited from class com.google.gson.JsonElement | +
---|
getAsJsonArray, getAsJsonNull, getAsJsonObject, getAsJsonPrimitive, isJsonArray, isJsonNull, isJsonObject, isJsonPrimitive, toString |
+
Methods inherited from class java.lang.Object | +
---|
equals, getClass, hashCode, notify, notifyAll, wait, wait, wait |
+
+Constructor Detail | +
---|
+public JsonArray()+
+
+Method Detail | +
---|
+public void add(JsonElement element)+
+
element
- the element that needs to be added to the array.+public void addAll(JsonArray array)+
+
array
- the array whose elements need to be added to the array.+public int size()+
+
+public Iterator<JsonElement> iterator()+
+
iterator
in interface Iterable<JsonElement>
+public JsonElement get(int i)+
+
i
- the index of the element that is being sought.
+IndexOutOfBoundsException
- if i is negative or greater than or equal to the
+ size()
of the array.+public Number getAsNumber()+
Number
if it contains a single element.
++
getAsNumber
in class JsonElement
ClassCastException
- if the element in the array is of not a JsonPrimitive
and
+ is not a valid Number.
+IllegalStateException
- if the array has more than one element.+public String getAsString()+
String
if it contains a single element.
++
getAsString
in class JsonElement
ClassCastException
- if the element in the array is of not a JsonPrimitive
and
+ is not a valid String.
+IllegalStateException
- if the array has more than one element.+public double getAsDouble()+
+
getAsDouble
in class JsonElement
ClassCastException
- if the element in the array is of not a JsonPrimitive
and
+ is not a valid double.
+IllegalStateException
- if the array has more than one element.+public BigDecimal getAsBigDecimal()+
BigDecimal
if it contains a single element.
++
getAsBigDecimal
in class JsonElement
BigDecimal
if it is single element array.
+ClassCastException
- if the element in the array is of not a JsonPrimitive
.
+NumberFormatException
- if the element at index 0 is not a valid BigDecimal
.
+IllegalStateException
- if the array has more than one element.+public BigInteger getAsBigInteger()+
BigInteger
if it contains a single element.
++
getAsBigInteger
in class JsonElement
BigInteger
if it is single element array.
+ClassCastException
- if the element in the array is of not a JsonPrimitive
.
+NumberFormatException
- if the element at index 0 is not a valid BigInteger
.
+IllegalStateException
- if the array has more than one element.+public float getAsFloat()+
+
getAsFloat
in class JsonElement
ClassCastException
- if the element in the array is of not a JsonPrimitive
and
+ is not a valid float.
+IllegalStateException
- if the array has more than one element.+public long getAsLong()+
+
getAsLong
in class JsonElement
ClassCastException
- if the element in the array is of not a JsonPrimitive
and
+ is not a valid long.
+IllegalStateException
- if the array has more than one element.+public int getAsInt()+
+
getAsInt
in class JsonElement
ClassCastException
- if the element in the array is of not a JsonPrimitive
and
+ is not a valid integer.
+IllegalStateException
- if the array has more than one element.+public byte getAsByte()+
JsonElement
+
getAsByte
in class JsonElement
+public char getAsCharacter()+
JsonElement
+
getAsCharacter
in class JsonElement
+public short getAsShort()+
+
getAsShort
in class JsonElement
ClassCastException
- if the element in the array is of not a JsonPrimitive
and
+ is not a valid short.
+IllegalStateException
- if the array has more than one element.+public boolean getAsBoolean()+
+
getAsBoolean
in class JsonElement
ClassCastException
- if the element in the array is of not a JsonPrimitive
and
+ is not a valid boolean.
+IllegalStateException
- if the array has more than one element.
+
+
|
++ + | +|||||||||
+ PREV CLASS + NEXT CLASS | ++ FRAMES + NO FRAMES + + + + + | +|||||||||
+ SUMMARY: NESTED | FIELD | CONSTR | METHOD | ++DETAIL: FIELD | CONSTR | METHOD | +
+
+
|
++ + | +|||||||||
+ PREV CLASS + NEXT CLASS | ++ FRAMES + NO FRAMES + + + + + | +|||||||||
+ SUMMARY: NESTED | FIELD | CONSTR | METHOD | ++DETAIL: FIELD | CONSTR | METHOD | +
public interface JsonDeserializationContext
+Context for deserialization that is passed to a custom deserializer during invocation of its
+ JsonDeserializer.deserialize(JsonElement, Type, JsonDeserializationContext)
+ method.
+
+ +
+
+Method Summary | +||
---|---|---|
+
+ |
+deserialize(JsonElement json,
+ Type typeOfT)
+
++ Invokes default deserialization on the specified object. |
+
+Method Detail | +
---|
+<T> T deserialize(JsonElement json, + Type typeOfT) + throws JsonParseException+
JsonDeserializer.deserialize(JsonElement, Type, JsonDeserializationContext)
method. Doing
+ so will result in an infinite loop since Gson will in-turn call the custom deserializer again.
++
T
- The type of the deserialized object.json
- the parse tree.typeOfT
- type of the expected return value.
+JsonParseException
- if the parse tree does not contain expected data.
+
+
|
++ + | +|||||||||
+ PREV CLASS + NEXT CLASS | ++ FRAMES + NO FRAMES + + + + + | +|||||||||
+ SUMMARY: NESTED | FIELD | CONSTR | METHOD | ++DETAIL: FIELD | CONSTR | METHOD | +
+
+
|
++ + | +|||||||||
+ PREV CLASS + NEXT CLASS | ++ FRAMES + NO FRAMES + + + + + | +|||||||||
+ SUMMARY: NESTED | FIELD | CONSTR | METHOD | ++DETAIL: FIELD | CONSTR | METHOD | +
T
- type for which the deserializer is being registered. It is possible that a
+ deserializer may be asked to deserialize a specific generic type of the T.public interface JsonDeserializer<T>
+
Interface representing a custom deserializer for Json. You should write a custom
+ deserializer, if you are not happy with the default deserialization done by Gson. You will
+ also need to register this deserializer through
+ GsonBuilder.registerTypeAdapter(Type, Object)
.
Let us look at example where defining a deserializer will be useful. The Id
class
+ defined below has two fields: clazz
and value
.
+ public class Id<T> { + private final Class<T> clazz; + private final long value; + public Id(Class<T> clazz, long value) { + this.clazz = clazz; + this.value = value; + } + public long getValue() { + return value; + } + } ++ +
The default deserialization of Id(com.foo.MyObject.class, 20L)
will require the
+ Json string to be {"clazz":com.foo.MyObject,"value":20}
. Suppose, you already know
+ the type of the field that the Id
will be deserialized into, and hence just want to
+ deserialize it from a Json string 20
. You can achieve that by writing a custom
+ deserializer:
+ class IdDeserializer implements JsonDeserializer<Id>() { + public Id fromJson(JsonElement json, Type typeOfT, JsonDeserializationContext context) + throws JsonParseException { + return (Id) new Id((Class)typeOfT, id.getValue()); + } ++ +
You will also need to register IdDeserializer
with Gson as follows:
+ Gson gson = new GsonBuilder().registerTypeAdapter(Id.class, new IdDeserializer()).create(); ++
+ +
+
+Method Summary | +|
---|---|
+ T |
+deserialize(JsonElement json,
+ Type typeOfT,
+ JsonDeserializationContext context)
+
++ Gson invokes this call-back method during deserialization when it encounters a field of the + specified type. |
+
+Method Detail | +
---|
+T deserialize(JsonElement json, + Type typeOfT, + JsonDeserializationContext context) + throws JsonParseException+
In the implementation of this call-back method, you should consider invoking
+ JsonDeserializationContext.deserialize(JsonElement, Type)
method to create objects
+ for any non-trivial field of the returned object. However, you should never invoke it on the
+ the same type passing json
since that will cause an infinite loop (Gson will call your
+ call-back method again).
+
+
json
- The Json data being deserializedtypeOfT
- The type of the Object to deserialize to
+T
+JsonParseException
- if json is not in the expected format of typeofT
+
+
|
++ + | +|||||||||
+ PREV CLASS + NEXT CLASS | ++ FRAMES + NO FRAMES + + + + + | +|||||||||
+ SUMMARY: NESTED | FIELD | CONSTR | METHOD | ++DETAIL: FIELD | CONSTR | METHOD | +
+
+
|
++ + | +|||||||||
+ PREV CLASS + NEXT CLASS | ++ FRAMES + NO FRAMES + + + + + | +|||||||||
+ SUMMARY: NESTED | FIELD | CONSTR | METHOD | ++DETAIL: FIELD | CONSTR | METHOD | +
+java.lang.Object + com.google.gson.JsonElement ++
public abstract class JsonElement
+A class representing an element of Json. It could either be a JsonObject
, a
+ JsonArray
, a JsonPrimitive
or a JsonNull
.
+
+ +
+
+Constructor Summary | +|
---|---|
JsonElement()
+
++ |
+
+Method Summary | +|
---|---|
+ BigDecimal |
+getAsBigDecimal()
+
++ convenience method to get this element as a BigDecimal . |
+
+ BigInteger |
+getAsBigInteger()
+
++ convenience method to get this element as a BigInteger . |
+
+ boolean |
+getAsBoolean()
+
++ convenience method to get this element as a boolean value. |
+
+ byte |
+getAsByte()
+
++ convenience method to get this element as a primitive byte value. |
+
+ char |
+getAsCharacter()
+
++ convenience method to get this element as a primitive character value. |
+
+ double |
+getAsDouble()
+
++ convenience method to get this element as a primitive double value. |
+
+ float |
+getAsFloat()
+
++ convenience method to get this element as a primitive float value. |
+
+ int |
+getAsInt()
+
++ convenience method to get this element as a primitive integer value. |
+
+ JsonArray |
+getAsJsonArray()
+
++ convenience method to get this element as a JsonArray . |
+
+ JsonNull |
+getAsJsonNull()
+
++ convenience method to get this element as a JsonNull . |
+
+ JsonObject |
+getAsJsonObject()
+
++ convenience method to get this element as a JsonObject . |
+
+ JsonPrimitive |
+getAsJsonPrimitive()
+
++ convenience method to get this element as a JsonPrimitive . |
+
+ long |
+getAsLong()
+
++ convenience method to get this element as a primitive long value. |
+
+ Number |
+getAsNumber()
+
++ convenience method to get this element as a Number . |
+
+ short |
+getAsShort()
+
++ convenience method to get this element as a primitive short value. |
+
+ String |
+getAsString()
+
++ convenience method to get this element as a string value. |
+
+ boolean |
+isJsonArray()
+
++ provides check for verifying if this element is an array or not. |
+
+ boolean |
+isJsonNull()
+
++ provides check for verifying if this element represents a null value or not. |
+
+ boolean |
+isJsonObject()
+
++ provides check for verifying if this element is a Json object or not. |
+
+ boolean |
+isJsonPrimitive()
+
++ provides check for verifying if this element is a primitive or not. |
+
+ String |
+toString()
+
++ Returns a String representation of this element. |
+
Methods inherited from class java.lang.Object | +
---|
equals, getClass, hashCode, notify, notifyAll, wait, wait, wait |
+
+Constructor Detail | +
---|
+public JsonElement()+
+Method Detail | +
---|
+public boolean isJsonArray()+
+
JsonArray
, false otherwise.+public boolean isJsonObject()+
+
JsonObject
, false otherwise.+public boolean isJsonPrimitive()+
+
JsonPrimitive
, false otherwise.+public boolean isJsonNull()+
+
JsonNull
, false otherwise.+public JsonObject getAsJsonObject()+
JsonObject
. If the element is of some
+ other type, a ClassCastException
will result. Hence it is best to use this method
+ after ensuring that this element is of the desired type by calling isJsonObject()
+ first.
++
JsonObject
.
+IllegalStateException
- if the element is of another type.+public JsonArray getAsJsonArray()+
JsonArray
. If the element is of some
+ other type, a ClassCastException
will result. Hence it is best to use this method
+ after ensuring that this element is of the desired type by calling isJsonArray()
+ first.
++
JsonArray
.
+IllegalStateException
- if the element is of another type.+public JsonPrimitive getAsJsonPrimitive()+
JsonPrimitive
. If the element is of some
+ other type, a ClassCastException
will result. Hence it is best to use this method
+ after ensuring that this element is of the desired type by calling isJsonPrimitive()
+ first.
++
JsonPrimitive
.
+IllegalStateException
- if the element is of another type.+public JsonNull getAsJsonNull()+
JsonNull
. If the element is of some
+ other type, a ClassCastException
will result. Hence it is best to use this method
+ after ensuring that this element is of the desired type by calling isJsonNull()
+ first.
++
JsonNull
.
+IllegalStateException
- if the element is of another type.+public boolean getAsBoolean()+
+
ClassCastException
- if the element is of not a JsonPrimitive
and is not a valid
+ boolean value.
+IllegalStateException
- if the element is of the type JsonArray
but contains
+ more than a single element.+public Number getAsNumber()+
Number
.
++
Number
.
+ClassCastException
- if the element is of not a JsonPrimitive
and is not a valid
+ number.
+IllegalStateException
- if the element is of the type JsonArray
but contains
+ more than a single element.+public String getAsString()+
+
ClassCastException
- if the element is of not a JsonPrimitive
and is not a valid
+ string value.
+IllegalStateException
- if the element is of the type JsonArray
but contains
+ more than a single element.+public double getAsDouble()+
+
ClassCastException
- if the element is of not a JsonPrimitive
and is not a valid
+ double value.
+IllegalStateException
- if the element is of the type JsonArray
but contains
+ more than a single element.+public float getAsFloat()+
+
ClassCastException
- if the element is of not a JsonPrimitive
and is not a valid
+ float value.
+IllegalStateException
- if the element is of the type JsonArray
but contains
+ more than a single element.+public long getAsLong()+
+
ClassCastException
- if the element is of not a JsonPrimitive
and is not a valid
+ long value.
+IllegalStateException
- if the element is of the type JsonArray
but contains
+ more than a single element.+public int getAsInt()+
+
ClassCastException
- if the element is of not a JsonPrimitive
and is not a valid
+ integer value.
+IllegalStateException
- if the element is of the type JsonArray
but contains
+ more than a single element.+public byte getAsByte()+
+
ClassCastException
- if the element is of not a JsonPrimitive
and is not a valid
+ byte value.
+IllegalStateException
- if the element is of the type JsonArray
but contains
+ more than a single element.+public char getAsCharacter()+
+
ClassCastException
- if the element is of not a JsonPrimitive
and is not a valid
+ char value.
+IllegalStateException
- if the element is of the type JsonArray
but contains
+ more than a single element.+public BigDecimal getAsBigDecimal()+
BigDecimal
.
++
BigDecimal
.
+ClassCastException
- if the element is of not a JsonPrimitive
.
+ * @throws NumberFormatException if the element is not a valid BigDecimal
.
+IllegalStateException
- if the element is of the type JsonArray
but contains
+ more than a single element.+public BigInteger getAsBigInteger()+
BigInteger
.
++
BigInteger
.
+ClassCastException
- if the element is of not a JsonPrimitive
.
+NumberFormatException
- if the element is not a valid BigInteger
.
+IllegalStateException
- if the element is of the type JsonArray
but contains
+ more than a single element.+public short getAsShort()+
+
ClassCastException
- if the element is of not a JsonPrimitive
and is not a valid
+ short value.
+IllegalStateException
- if the element is of the type JsonArray
but contains
+ more than a single element.+public String toString()+
+
toString
in class Object
+
+
|
++ + | +|||||||||
+ PREV CLASS + NEXT CLASS | ++ FRAMES + NO FRAMES + + + + + | +|||||||||
+ SUMMARY: NESTED | FIELD | CONSTR | METHOD | ++DETAIL: FIELD | CONSTR | METHOD | +
+
+
|
++ + | +|||||||||
+ PREV CLASS + NEXT CLASS | ++ FRAMES + NO FRAMES + + + + + | +|||||||||
+ SUMMARY: NESTED | FIELD | CONSTR | METHOD | ++DETAIL: FIELD | CONSTR | METHOD | +
+java.lang.Object + java.lang.Throwable + java.lang.Exception + java.lang.RuntimeException + com.google.gson.JsonParseException + com.google.gson.JsonIOException ++
public final class JsonIOException
+This exception is raised when Gson was unable to read an input stream + or write to one. +
+ +
+
+Constructor Summary | +|
---|---|
JsonIOException(String msg)
+
++ |
+|
JsonIOException(String msg,
+ Throwable cause)
+
++ |
+|
JsonIOException(Throwable cause)
+
++ Creates exception with the specified cause. |
+
+Method Summary | +
---|
Methods inherited from class java.lang.Throwable | +
---|
fillInStackTrace, getCause, getLocalizedMessage, getMessage, getStackTrace, initCause, printStackTrace, printStackTrace, printStackTrace, setStackTrace, toString |
+
Methods inherited from class java.lang.Object | +
---|
equals, getClass, hashCode, notify, notifyAll, wait, wait, wait |
+
+Constructor Detail | +
---|
+public JsonIOException(String msg)+
+public JsonIOException(String msg, + Throwable cause)+
+public JsonIOException(Throwable cause)+
JsonIOException(String, Throwable)
instead if you can describe what happened.
++
cause
- root exception that caused this exception to be thrown.
+
+
|
++ + | +|||||||||
+ PREV CLASS + NEXT CLASS | ++ FRAMES + NO FRAMES + + + + + | +|||||||||
+ SUMMARY: NESTED | FIELD | CONSTR | METHOD | ++DETAIL: FIELD | CONSTR | METHOD | +
+
+
|
++ + | +|||||||||
+ PREV CLASS + NEXT CLASS | ++ FRAMES + NO FRAMES + + + + + | +|||||||||
+ SUMMARY: NESTED | FIELD | CONSTR | METHOD | ++DETAIL: FIELD | CONSTR | METHOD | +
+java.lang.Object + com.google.gson.JsonElement + com.google.gson.JsonNull ++
public final class JsonNull
+A class representing a Json null
value.
+
+ +
+
+Constructor Summary | +|
---|---|
JsonNull()
+
++ Creates a new JsonNull object. |
+
+Method Summary | +|
---|---|
+ boolean |
+equals(Object other)
+
++ All instances of JsonNull are the same |
+
+ int |
+hashCode()
+
++ All instances of JsonNull have the same hash code since they are indistinguishable |
+
Methods inherited from class com.google.gson.JsonElement | +
---|
getAsBigDecimal, getAsBigInteger, getAsBoolean, getAsByte, getAsCharacter, getAsDouble, getAsFloat, getAsInt, getAsJsonArray, getAsJsonNull, getAsJsonObject, getAsJsonPrimitive, getAsLong, getAsNumber, getAsShort, getAsString, isJsonArray, isJsonNull, isJsonObject, isJsonPrimitive, toString |
+
Methods inherited from class java.lang.Object | +
---|
getClass, notify, notifyAll, wait, wait, wait |
+
+Constructor Detail | +
---|
+public JsonNull()+
+
+Method Detail | +
---|
+public int hashCode()+
+
hashCode
in class Object
+public boolean equals(Object other)+
+
equals
in class Object
+
+
|
++ + | +|||||||||
+ PREV CLASS + NEXT CLASS | ++ FRAMES + NO FRAMES + + + + + | +|||||||||
+ SUMMARY: NESTED | FIELD | CONSTR | METHOD | ++DETAIL: FIELD | CONSTR | METHOD | +
+
+
|
++ + | +|||||||||
+ PREV CLASS + NEXT CLASS | ++ FRAMES + NO FRAMES + + + + + | +|||||||||
+ SUMMARY: NESTED | FIELD | CONSTR | METHOD | ++DETAIL: FIELD | CONSTR | METHOD | +
+java.lang.Object + com.google.gson.JsonElement + com.google.gson.JsonObject ++
public final class JsonObject
+A class representing an object type in Json. An object consists of name-value pairs where names
+ are strings, and values are any other type of JsonElement
. This allows for a creating a
+ tree of JsonElements. The member elements of this object are maintained in order they were added.
+
+ +
+
+Constructor Summary | +|
---|---|
JsonObject()
+
++ Creates an empty JsonObject. |
+
+Method Summary | +|
---|---|
+ void |
+add(String property,
+ JsonElement value)
+
++ Adds a member, which is a name-value pair, to self. |
+
+ void |
+addProperty(String property,
+ Boolean value)
+
++ Convenience method to add a boolean member. |
+
+ void |
+addProperty(String property,
+ Character value)
+
++ Convenience method to add a char member. |
+
+ void |
+addProperty(String property,
+ Number value)
+
++ Convenience method to add a primitive member. |
+
+ void |
+addProperty(String property,
+ String value)
+
++ Convenience method to add a primitive member. |
+
+ Set<Map.Entry<String,JsonElement>> |
+entrySet()
+
++ Returns a set of members of this object. |
+
+ JsonElement |
+get(String memberName)
+
++ Returns the member with the specified name. |
+
+ JsonArray |
+getAsJsonArray(String memberName)
+
++ Convenience method to get the specified member as a JsonArray. |
+
+ JsonObject |
+getAsJsonObject(String memberName)
+
++ Convenience method to get the specified member as a JsonObject. |
+
+ JsonPrimitive |
+getAsJsonPrimitive(String memberName)
+
++ Convenience method to get the specified member as a JsonPrimitive element. |
+
+ boolean |
+has(String memberName)
+
++ Convenience method to check if a member with the specified name is present in this object. |
+
+ JsonElement |
+remove(String property)
+
++ Removes the property from this JsonObject . |
+
Methods inherited from class com.google.gson.JsonElement | +
---|
getAsBigDecimal, getAsBigInteger, getAsBoolean, getAsByte, getAsCharacter, getAsDouble, getAsFloat, getAsInt, getAsJsonArray, getAsJsonNull, getAsJsonObject, getAsJsonPrimitive, getAsLong, getAsNumber, getAsShort, getAsString, isJsonArray, isJsonNull, isJsonObject, isJsonPrimitive, toString |
+
Methods inherited from class java.lang.Object | +
---|
equals, getClass, hashCode, notify, notifyAll, wait, wait, wait |
+
+Constructor Detail | +
---|
+public JsonObject()+
+
+Method Detail | +
---|
+public void add(String property, + JsonElement value)+
+
property
- name of the member.value
- the member object.+public JsonElement remove(String property)+
property
from this JsonObject
.
++
property
- name of the member that should be removed.
+JsonElement
object that is being removed.+public void addProperty(String property, + String value)+
+
property
- name of the member.value
- the string value associated with the member.+public void addProperty(String property, + Number value)+
+
property
- name of the member.value
- the number value associated with the member.+public void addProperty(String property, + Boolean value)+
+
property
- name of the member.value
- the number value associated with the member.+public void addProperty(String property, + Character value)+
+
property
- name of the member.value
- the number value associated with the member.+public Set<Map.Entry<String,JsonElement>> entrySet()+
+
+public boolean has(String memberName)+
+
memberName
- name of the member that is being checked for presence.
++public JsonElement get(String memberName)+
+
memberName
- name of the member that is being requested.
++public JsonPrimitive getAsJsonPrimitive(String memberName)+
+
memberName
- name of the member being requested.
++public JsonArray getAsJsonArray(String memberName)+
+
memberName
- name of the member being requested.
++public JsonObject getAsJsonObject(String memberName)+
+
memberName
- name of the member being requested.
+
+
+
|
++ + | +|||||||||
+ PREV CLASS + NEXT CLASS | ++ FRAMES + NO FRAMES + + + + + | +|||||||||
+ SUMMARY: NESTED | FIELD | CONSTR | METHOD | ++DETAIL: FIELD | CONSTR | METHOD | +
+
+
|
++ + | +|||||||||
+ PREV CLASS + NEXT CLASS | ++ FRAMES + NO FRAMES + + + + + | +|||||||||
+ SUMMARY: NESTED | FIELD | CONSTR | METHOD | ++DETAIL: FIELD | CONSTR | METHOD | +
+java.lang.Object + java.lang.Throwable + java.lang.Exception + java.lang.RuntimeException + com.google.gson.JsonParseException ++
public class JsonParseException
+This exception is raised if there is a serious issue that occurs during parsing of a Json + string. One of the main usages for this class is for the Gson infrastructure. If the incoming + Json is bad/malicious, an instance of this exception is raised. + +
This exception is a RuntimeException
because it is exposed to the client. Using a
+ RuntimeException
avoids bad coding practices on the client side where they catch the
+ exception and do nothing. It is often the case that you want to blow up if there is a parsing
+ error (i.e. often clients do not know how to recover from a JsonParseException
.
+ +
+
+Constructor Summary | +|
---|---|
JsonParseException(String msg)
+
++ Creates exception with the specified message. |
+|
JsonParseException(String msg,
+ Throwable cause)
+
++ Creates exception with the specified message and cause. |
+|
JsonParseException(Throwable cause)
+
++ Creates exception with the specified cause. |
+
+Method Summary | +
---|
Methods inherited from class java.lang.Throwable | +
---|
fillInStackTrace, getCause, getLocalizedMessage, getMessage, getStackTrace, initCause, printStackTrace, printStackTrace, printStackTrace, setStackTrace, toString |
+
Methods inherited from class java.lang.Object | +
---|
equals, getClass, hashCode, notify, notifyAll, wait, wait, wait |
+
+Constructor Detail | +
---|
+public JsonParseException(String msg)+
JsonParseException(String, Throwable)
instead.
++
msg
- error message describing a possible cause of this exception.+public JsonParseException(String msg, + Throwable cause)+
+
msg
- error message describing what happened.cause
- root exception that caused this exception to be thrown.+public JsonParseException(Throwable cause)+
JsonParseException(String, Throwable)
instead if you can describe what happened.
++
cause
- root exception that caused this exception to be thrown.
+
+
|
++ + | +|||||||||
+ PREV CLASS + NEXT CLASS | ++ FRAMES + NO FRAMES + + + + + | +|||||||||
+ SUMMARY: NESTED | FIELD | CONSTR | METHOD | ++DETAIL: FIELD | CONSTR | METHOD | +
+
+
|
++ + | +|||||||||
+ PREV CLASS + NEXT CLASS | ++ FRAMES + NO FRAMES + + + + + | +|||||||||
+ SUMMARY: NESTED | FIELD | CONSTR | METHOD | ++DETAIL: FIELD | CONSTR | METHOD | +
+java.lang.Object + com.google.gson.JsonParser ++
public final class JsonParser
+A parser to parse Json into a parse tree of JsonElement
s
+
+ +
+
+Constructor Summary | +|
---|---|
JsonParser()
+
++ |
+
+Method Summary | +|
---|---|
+ JsonElement |
+parse(JsonReader json)
+
++ Returns the next value from the JSON stream as a parse tree. |
+
+ JsonElement |
+parse(Reader json)
+
++ Parses the specified JSON string into a parse tree |
+
+ JsonElement |
+parse(String json)
+
++ Parses the specified JSON string into a parse tree |
+
Methods inherited from class java.lang.Object | +
---|
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
+
+Constructor Detail | +
---|
+public JsonParser()+
+Method Detail | +
---|
+public JsonElement parse(String json) + throws JsonSyntaxException+
+
json
- JSON text
+JsonElement
s corresponding to the specified JSON
+JsonParseException
- if the specified text is not valid JSON
+JsonSyntaxException
+public JsonElement parse(Reader json) + throws JsonIOException, + JsonSyntaxException+
+
json
- JSON text
+JsonElement
s corresponding to the specified JSON
+JsonParseException
- if the specified text is not valid JSON
+JsonIOException
+JsonSyntaxException
+public JsonElement parse(JsonReader json) + throws JsonIOException, + JsonSyntaxException+
+
JsonParseException
- if there is an IOException or if the specified
+ text is not valid JSON
+JsonIOException
+JsonSyntaxException
+
+
|
++ + | +|||||||||
+ PREV CLASS + NEXT CLASS | ++ FRAMES + NO FRAMES + + + + + | +|||||||||
+ SUMMARY: NESTED | FIELD | CONSTR | METHOD | ++DETAIL: FIELD | CONSTR | METHOD | +
+
+
|
++ + | +|||||||||
+ PREV CLASS + NEXT CLASS | ++ FRAMES + NO FRAMES + + + + + | +|||||||||
+ SUMMARY: NESTED | FIELD | CONSTR | METHOD | ++DETAIL: FIELD | CONSTR | METHOD | +
+java.lang.Object + com.google.gson.JsonElement + com.google.gson.JsonPrimitive ++
public final class JsonPrimitive
+A class representing a Json primitive value. A primitive value + is either a String, a Java primitive, or a Java primitive + wrapper type. +
+ +
+
+Constructor Summary | +|
---|---|
JsonPrimitive(Boolean bool)
+
++ Create a primitive containing a boolean value. |
+|
JsonPrimitive(Character c)
+
++ Create a primitive containing a character. |
+|
JsonPrimitive(Number number)
+
++ Create a primitive containing a Number . |
+|
JsonPrimitive(String string)
+
++ Create a primitive containing a String value. |
+
+Method Summary | +|
---|---|
+ boolean |
+equals(Object obj)
+
++ |
+
+ BigDecimal |
+getAsBigDecimal()
+
++ convenience method to get this element as a BigDecimal . |
+
+ BigInteger |
+getAsBigInteger()
+
++ convenience method to get this element as a BigInteger . |
+
+ boolean |
+getAsBoolean()
+
++ convenience method to get this element as a boolean value. |
+
+ byte |
+getAsByte()
+
++ convenience method to get this element as a primitive byte value. |
+
+ char |
+getAsCharacter()
+
++ convenience method to get this element as a primitive character value. |
+
+ double |
+getAsDouble()
+
++ convenience method to get this element as a primitive double. |
+
+ float |
+getAsFloat()
+
++ convenience method to get this element as a float. |
+
+ int |
+getAsInt()
+
++ convenience method to get this element as a primitive integer. |
+
+ long |
+getAsLong()
+
++ convenience method to get this element as a primitive long. |
+
+ Number |
+getAsNumber()
+
++ convenience method to get this element as a Number. |
+
+ short |
+getAsShort()
+
++ convenience method to get this element as a primitive short. |
+
+ String |
+getAsString()
+
++ convenience method to get this element as a String. |
+
+ int |
+hashCode()
+
++ |
+
+ boolean |
+isBoolean()
+
++ Check whether this primitive contains a boolean value. |
+
+ boolean |
+isNumber()
+
++ Check whether this primitive contains a Number. |
+
+ boolean |
+isString()
+
++ Check whether this primitive contains a String value. |
+
Methods inherited from class com.google.gson.JsonElement | +
---|
getAsJsonArray, getAsJsonNull, getAsJsonObject, getAsJsonPrimitive, isJsonArray, isJsonNull, isJsonObject, isJsonPrimitive, toString |
+
Methods inherited from class java.lang.Object | +
---|
getClass, notify, notifyAll, wait, wait, wait |
+
+Constructor Detail | +
---|
+public JsonPrimitive(Boolean bool)+
+
bool
- the value to create the primitive with.+public JsonPrimitive(Number number)+
Number
.
++
number
- the value to create the primitive with.+public JsonPrimitive(String string)+
+
string
- the value to create the primitive with.+public JsonPrimitive(Character c)+
+
c
- the value to create the primitive with.+Method Detail | +
---|
+public boolean isBoolean()+
+
+public boolean getAsBoolean()+
+
getAsBoolean
in class JsonElement
ClassCastException
- if the value contained is not a valid boolean value.+public boolean isNumber()+
+
+public Number getAsNumber()+
+
getAsNumber
in class JsonElement
ClassCastException
- if the value contained is not a valid Number.+public boolean isString()+
+
+public String getAsString()+
+
getAsString
in class JsonElement
ClassCastException
- if the value contained is not a valid String.+public double getAsDouble()+
+
getAsDouble
in class JsonElement
ClassCastException
- if the value contained is not a valid double.+public BigDecimal getAsBigDecimal()+
BigDecimal
.
++
getAsBigDecimal
in class JsonElement
BigDecimal
.
+NumberFormatException
- if the value contained is not a valid BigDecimal
.+public BigInteger getAsBigInteger()+
BigInteger
.
++
getAsBigInteger
in class JsonElement
BigInteger
.
+NumberFormatException
- if the value contained is not a valid BigInteger
.+public float getAsFloat()+
+
getAsFloat
in class JsonElement
ClassCastException
- if the value contained is not a valid float.+public long getAsLong()+
+
getAsLong
in class JsonElement
ClassCastException
- if the value contained is not a valid long.+public short getAsShort()+
+
getAsShort
in class JsonElement
ClassCastException
- if the value contained is not a valid short value.+public int getAsInt()+
+
getAsInt
in class JsonElement
ClassCastException
- if the value contained is not a valid integer.+public byte getAsByte()+
JsonElement
+
getAsByte
in class JsonElement
+public char getAsCharacter()+
JsonElement
+
getAsCharacter
in class JsonElement
+public int hashCode()+
hashCode
in class Object
+public boolean equals(Object obj)+
equals
in class Object
+
+
|
++ + | +|||||||||
+ PREV CLASS + NEXT CLASS | ++ FRAMES + NO FRAMES + + + + + | +|||||||||
+ SUMMARY: NESTED | FIELD | CONSTR | METHOD | ++DETAIL: FIELD | CONSTR | METHOD | +
+
+
|
++ + | +|||||||||
+ PREV CLASS + NEXT CLASS | ++ FRAMES + NO FRAMES + + + + + | +|||||||||
+ SUMMARY: NESTED | FIELD | CONSTR | METHOD | ++DETAIL: FIELD | CONSTR | METHOD | +
public interface JsonSerializationContext
+Context for serialization that is passed to a custom serializer during invocation of its
+ JsonSerializer.serialize(Object, Type, JsonSerializationContext)
method.
+
+ +
+
+Method Summary | +|
---|---|
+ JsonElement |
+serialize(Object src)
+
++ Invokes default serialization on the specified object. |
+
+ JsonElement |
+serialize(Object src,
+ Type typeOfSrc)
+
++ Invokes default serialization on the specified object passing the specific type information. |
+
+Method Detail | +
---|
+JsonElement serialize(Object src)+
+
src
- the object that needs to be serialized.
+JsonElement
s corresponding to the serialized form of src
.+JsonElement serialize(Object src, + Type typeOfSrc)+
JsonSerializer.serialize(Object, Type, JsonSerializationContext)
method. Doing
+ so will result in an infinite loop since Gson will in-turn call the custom serializer again.
++
src
- the object that needs to be serialized.typeOfSrc
- the actual genericized type of src object.
+JsonElement
s corresponding to the serialized form of src
.
+
+
|
++ + | +|||||||||
+ PREV CLASS + NEXT CLASS | ++ FRAMES + NO FRAMES + + + + + | +|||||||||
+ SUMMARY: NESTED | FIELD | CONSTR | METHOD | ++DETAIL: FIELD | CONSTR | METHOD | +
+
+
|
++ + | +|||||||||
+ PREV CLASS + NEXT CLASS | ++ FRAMES + NO FRAMES + + + + + | +|||||||||
+ SUMMARY: NESTED | FIELD | CONSTR | METHOD | ++DETAIL: FIELD | CONSTR | METHOD | +
T
- type for which the serializer is being registered. It is possible that a serializer
+ may be asked to serialize a specific generic type of the T.public interface JsonSerializer<T>
+Interface representing a custom serializer for Json. You should write a custom serializer, if
+ you are not happy with the default serialization done by Gson. You will also need to register
+ this serializer through GsonBuilder.registerTypeAdapter(Type, Object)
.
+
+
Let us look at example where defining a serializer will be useful. The Id
class
+ defined below has two fields: clazz
and value
.
+ public class Id<T> { + private final Class<T> clazz; + private final long value; + + public Id(Class<T> clazz, long value) { + this.clazz = clazz; + this.value = value; + } + + public long getValue() { + return value; + } + } ++ +
The default serialization of Id(com.foo.MyObject.class, 20L)
will be
+ {"clazz":com.foo.MyObject,"value":20}
. Suppose, you just want the output to be
+ the value instead, which is 20
in this case. You can achieve that by writing a custom
+ serializer:
+ class IdSerializer implements JsonSerializer<Id>() { + public JsonElement toJson(Id id, Type typeOfId, JsonSerializationContext context) { + return new JsonPrimitive(id.getValue()); + } + } ++ +
You will also need to register IdSerializer
with Gson as follows:
+ Gson gson = new GsonBuilder().registerTypeAdapter(Id.class, new IdSerializer()).create(); ++
+ +
+
+Method Summary | +|
---|---|
+ JsonElement |
+serialize(T src,
+ Type typeOfSrc,
+ JsonSerializationContext context)
+
++ Gson invokes this call-back method during serialization when it encounters a field of the + specified type. |
+
+Method Detail | +
---|
+JsonElement serialize(T src, + Type typeOfSrc, + JsonSerializationContext context)+
In the implementation of this call-back method, you should consider invoking
+ JsonSerializationContext.serialize(Object, Type)
method to create JsonElements for any
+ non-trivial field of the src
object. However, you should never invoke it on the
+ src
object itself since that will cause an infinite loop (Gson will call your
+ call-back method again).
+
src
- the object that needs to be converted to Json.typeOfSrc
- the actual type (fully genericized version) of the source object.
+
+
+
|
++ + | +|||||||||
+ PREV CLASS + NEXT CLASS | ++ FRAMES + NO FRAMES + + + + + | +|||||||||
+ SUMMARY: NESTED | FIELD | CONSTR | METHOD | ++DETAIL: FIELD | CONSTR | METHOD | +
+
+
|
++ + | +|||||||||
+ PREV CLASS + NEXT CLASS | ++ FRAMES + NO FRAMES + + + + + | +|||||||||
+ SUMMARY: NESTED | FIELD | CONSTR | METHOD | ++DETAIL: FIELD | CONSTR | METHOD | +
+java.lang.Object + com.google.gson.JsonStreamParser ++
public final class JsonStreamParser
+A streaming parser that allows reading of multiple JsonElement
s from the specified reader
+ asynchronously.
+
+
This class is conditionally thread-safe (see Item 70, Effective Java second edition). To + properly use this class across multiple threads, you will need to add some external + synchronization. For example: + +
+ JsonStreamParser parser = new JsonStreamParser("['first'] {'second':10} 'third'"); + JsonElement element; + synchronized (parser) { // synchronize on an object shared by threads + if (parser.hasNext()) { + element = parser.next(); + } + } ++
+ +
+
+Constructor Summary | +|
---|---|
JsonStreamParser(Reader reader)
+
++ |
+|
JsonStreamParser(String json)
+
++ |
+
+Method Summary | +|
---|---|
+ boolean |
+hasNext()
+
++ Returns true if a JsonElement is available on the input for consumption |
+
+ JsonElement |
+next()
+
++ Returns the next available JsonElement on the reader. |
+
+ void |
+remove()
+
++ This optional Iterator method is not relevant for stream parsing and hence is not
+ implemented. |
+
Methods inherited from class java.lang.Object | +
---|
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
+
+Constructor Detail | +
---|
+public JsonStreamParser(String json)+
json
- The string containing JSON elements concatenated to each other.+public JsonStreamParser(Reader reader)+
reader
- The data stream containing JSON elements concatenated to each other.+Method Detail | +
---|
+public JsonElement next() + throws JsonParseException+
JsonElement
on the reader. Null if none available.
++
next
in interface Iterator<JsonElement>
JsonElement
on the reader. Null if none available.
+JsonParseException
- if the incoming stream is malformed JSON.+public boolean hasNext()+
JsonElement
is available on the input for consumption
++
hasNext
in interface Iterator<JsonElement>
JsonElement
is available on the input, false otherwise+public void remove()+
Iterator
method is not relevant for stream parsing and hence is not
+ implemented.
++
remove
in interface Iterator<JsonElement>
+
+
|
++ + | +|||||||||
+ PREV CLASS + NEXT CLASS | ++ FRAMES + NO FRAMES + + + + + | +|||||||||
+ SUMMARY: NESTED | FIELD | CONSTR | METHOD | ++DETAIL: FIELD | CONSTR | METHOD | +
+
+
|
++ + | +|||||||||
+ PREV CLASS + NEXT CLASS | ++ FRAMES + NO FRAMES + + + + + | +|||||||||
+ SUMMARY: NESTED | FIELD | CONSTR | METHOD | ++DETAIL: FIELD | CONSTR | METHOD | +
+java.lang.Object + java.lang.Throwable + java.lang.Exception + java.lang.RuntimeException + com.google.gson.JsonParseException + com.google.gson.JsonSyntaxException ++
public final class JsonSyntaxException
+This exception is raised when Gson attempts to read (or write) a malformed + JSON element. +
+ +
+
+Constructor Summary | +|
---|---|
JsonSyntaxException(String msg)
+
++ |
+|
JsonSyntaxException(String msg,
+ Throwable cause)
+
++ |
+|
JsonSyntaxException(Throwable cause)
+
++ Creates exception with the specified cause. |
+
+Method Summary | +
---|
Methods inherited from class java.lang.Throwable | +
---|
fillInStackTrace, getCause, getLocalizedMessage, getMessage, getStackTrace, initCause, printStackTrace, printStackTrace, printStackTrace, setStackTrace, toString |
+
Methods inherited from class java.lang.Object | +
---|
equals, getClass, hashCode, notify, notifyAll, wait, wait, wait |
+
+Constructor Detail | +
---|
+public JsonSyntaxException(String msg)+
+public JsonSyntaxException(String msg, + Throwable cause)+
+public JsonSyntaxException(Throwable cause)+
JsonSyntaxException(String, Throwable)
instead if you can
+ describe what actually happened.
++
cause
- root exception that caused this exception to be thrown.
+
+
|
++ + | +|||||||||
+ PREV CLASS + NEXT CLASS | ++ FRAMES + NO FRAMES + + + + + | +|||||||||
+ SUMMARY: NESTED | FIELD | CONSTR | METHOD | ++DETAIL: FIELD | CONSTR | METHOD | +
+
+
|
++ + | +|||||||||
+ PREV CLASS + NEXT CLASS | ++ FRAMES + NO FRAMES + + + + + | +|||||||||
+ SUMMARY: NESTED | ENUM CONSTANTS | FIELD | METHOD | ++DETAIL: ENUM CONSTANTS | FIELD | METHOD | +
+java.lang.Object + java.lang.Enum<LongSerializationPolicy> + com.google.gson.LongSerializationPolicy ++
public enum LongSerializationPolicy
+Defines the expected format for a long
or Long
type when its serialized.
+
+ +
+
+Enum Constant Summary | +|
---|---|
DEFAULT
+
++ This is the "default" serialization policy that will output a long object as a JSON
+ number. |
+|
STRING
+
++ Serializes a long value as a quoted string. |
+
+Method Summary | +|
---|---|
+ JsonElement |
+serialize(Long value)
+
++ Serialize this value using this serialization policy. |
+
+static LongSerializationPolicy |
+valueOf(String name)
+
++ Returns the enum constant of this type with the specified name. |
+
+static LongSerializationPolicy[] |
+values()
+
++ Returns an array containing the constants of this enum type, in +the order they are declared. |
+
Methods inherited from class java.lang.Enum | +
---|
compareTo, equals, getDeclaringClass, hashCode, name, ordinal, toString, valueOf |
+
Methods inherited from class java.lang.Object | +
---|
getClass, notify, notifyAll, wait, wait, wait |
+
+Enum Constant Detail | +
---|
+public static final LongSerializationPolicy DEFAULT+
long
object as a JSON
+ number. For example, assume an object has a long field named "f" then the serialized output
+ would be:
+ {"f":123}
.
++
+public static final LongSerializationPolicy STRING+
{"f":"123"}
.
++
+Method Detail | +
---|
+public static LongSerializationPolicy[] values()+
+for (LongSerializationPolicy c : LongSerializationPolicy.values()) + System.out.println(c); ++
+
+public static LongSerializationPolicy valueOf(String name)+
+
name
- the name of the enum constant to be returned.
+IllegalArgumentException
- if this enum type has no constant
+with the specified name
+NullPointerException
- if the argument is null+public JsonElement serialize(Long value)+
value
using this serialization policy.
++
value
- the long value to be serialized into a JsonElement
+value
+
+
|
++ + | +|||||||||
+ PREV CLASS + NEXT CLASS | ++ FRAMES + NO FRAMES + + + + + | +|||||||||
+ SUMMARY: NESTED | ENUM CONSTANTS | FIELD | METHOD | ++DETAIL: ENUM CONSTANTS | FIELD | METHOD | +
+
+
|
++ + | +|||||||||
+ PREV CLASS + NEXT CLASS | ++ FRAMES + NO FRAMES + + + + + | +|||||||||
+ SUMMARY: REQUIRED | OPTIONAL | ++DETAIL: ELEMENT | +
@Retention(value=RUNTIME) +@Target(value=FIELD) +public @interface Expose
+An annotation that indicates this member should be exposed for JSON + serialization or deserialization. + +
This annotation has no effect unless you build Gson
+ with a GsonBuilder
and invoke
+ GsonBuilder.excludeFieldsWithoutExposeAnnotation()
+ method.
Here is an example of how this annotation is meant to be used: +
+ public class User { + @Expose private String firstName; + @Expose(serialize = false) private String lastName; + @Expose (serialize = false, deserialize = false) private String emailAddress; + private String password; + } ++ If you created Gson with
new Gson()
, the toJson()
and fromJson()
+ methods will use the password
field along-with firstName
, lastName
,
+ and emailAddress
for serialization and deserialization. However, if you created Gson
+ with Gson gson = new GsonBuilder().excludeFieldsWithoutExposeAnnotation().create()
+ then the toJson()
and fromJson()
methods of Gson will exclude the
+ password
field. This is because the password
field is not marked with the
+ @Expose
annotation. Gson will also exclude lastName
and emailAddress
+ from serialization since serialize
is set to false
. Similarly, Gson will
+ exclude emailAddress
from deserialization since deserialize
is set to false.
+
+ Note that another way to achieve the same effect would have been to just mark the
+ password
field as transient
, and Gson would have excluded it even with default
+ settings. The @Expose
annotation is useful in a style of programming where you want to
+ explicitly specify all fields that should get considered for serialization or deserialization.
+
+ +
+
+Optional Element Summary | +|
---|---|
+ boolean |
+deserialize
+
++ If true , the field marked with this annotation is deserialized from the JSON. |
+
+ boolean |
+serialize
+
++ If true , the field marked with this annotation is written out in the JSON while
+ serializing. |
+
+public abstract boolean serialize+
true
, the field marked with this annotation is written out in the JSON while
+ serializing. If false
, the field marked with this annotation is skipped from the
+ serialized output. Defaults to true
.
++
+public abstract boolean deserialize+
true
, the field marked with this annotation is deserialized from the JSON.
+ If false
, the field marked with this annotation is skipped during deserialization.
+ Defaults to true
.
++
+
+
|
++ + | +|||||||||
+ PREV CLASS + NEXT CLASS | ++ FRAMES + NO FRAMES + + + + + | +|||||||||
+ SUMMARY: REQUIRED | OPTIONAL | ++DETAIL: ELEMENT | +
+
+
|
++ + | +|||||||||
+ PREV CLASS + NEXT CLASS | ++ FRAMES + NO FRAMES + + + + + | +|||||||||
+ SUMMARY: REQUIRED | OPTIONAL | ++DETAIL: ELEMENT | +
@Retention(value=RUNTIME) +@Target(value=FIELD) +public @interface SerializedName
+An annotation that indicates this member should be serialized to JSON with + the provided name value as its field name. + +
This annotation will override any FieldNamingPolicy
, including
+ the default field naming policy, that may have been set on the Gson
+ instance. A different naming policy can set using the GsonBuilder
class. See
+ GsonBuilder.setFieldNamingPolicy(com.google.gson.FieldNamingPolicy)
+ for more information.
Here is an example of how this annotation is meant to be used:
++ public class SomeClassWithFields { + @SerializedName("name") private final String someField; + private final String someOtherField; + + public SomeClassWithFields(String a, String b) { + this.someField = a; + this.someOtherField = b; + } + } ++ +
The following shows the output that is generated when serializing an instance of the + above example class:
++ SomeClassWithFields objectToSerialize = new SomeClassWithFields("a", "b"); + Gson gson = new Gson(); + String jsonRepresentation = gson.toJson(objectToSerialize); + System.out.println(jsonRepresentation); + + ===== OUTPUT ===== + {"name":"a","someOtherField":"b"} ++ +
NOTE: The value you specify in this annotation must be a valid JSON field name.
++ +
+
FieldNamingPolicy
+Required Element Summary | +|
---|---|
+ String |
+value
+
++ |
+
+Element Detail | +
---|
+public abstract String value+
+
+
|
++ + | +|||||||||
+ PREV CLASS + NEXT CLASS | ++ FRAMES + NO FRAMES + + + + + | +|||||||||
+ SUMMARY: REQUIRED | OPTIONAL | ++DETAIL: ELEMENT | +
+
+
|
++ + | +|||||||||
+ PREV CLASS + NEXT CLASS | ++ FRAMES + NO FRAMES + + + + + | +|||||||||
+ SUMMARY: REQUIRED | OPTIONAL | ++DETAIL: ELEMENT | +
@Retention(value=RUNTIME) +@Target(value={FIELD,TYPE}) +public @interface Since
+An annotation that indicates the version number since a member or a type has been present. + This annotation is useful to manage versioning of your Json classes for a web-service. + +
+ This annotation has no effect unless you build Gson
with a
+ GsonBuilder
and invoke
+ GsonBuilder.setVersion(double)
method.
+
+
Here is an example of how this annotation is meant to be used:
++ public class User { + private String firstName; + private String lastName; + @Since(1.0) private String emailAddress; + @Since(1.0) private String password; + @Since(1.1) private Address address; + } ++ +
If you created Gson with new Gson()
, the toJson()
and fromJson()
+ methods will use all the fields for serialization and deserialization. However, if you created
+ Gson with Gson gson = new GsonBuilder().setVersion(1.0).create()
then the
+ toJson()
and fromJson()
methods of Gson will exclude the address
field
+ since it's version number is set to 1.1
.
+ +
+
+Required Element Summary | +|
---|---|
+ double |
+value
+
++ the value indicating a version number since this member + or type has been present. |
+
+Element Detail | +
---|
+public abstract double value+
+
+
+
|
++ + | +|||||||||
+ PREV CLASS + NEXT CLASS | ++ FRAMES + NO FRAMES + + + + + | +|||||||||
+ SUMMARY: REQUIRED | OPTIONAL | ++DETAIL: ELEMENT | +
+
+
|
++ + | +|||||||||
+ PREV CLASS + NEXT CLASS | ++ FRAMES + NO FRAMES + + + + + | +|||||||||
+ SUMMARY: REQUIRED | OPTIONAL | ++DETAIL: ELEMENT | +
@Retention(value=RUNTIME) +@Target(value={FIELD,TYPE}) +public @interface Until
+An annotation that indicates the version number until a member or a type should be present.
+ Basically, if Gson is created with a version number that exceeds the value stored in the
+ Until
annotation then the field will be ignored from the JSON output. This annotation
+ is useful to manage versioning of your JSON classes for a web-service.
+
+
+ This annotation has no effect unless you build Gson
with a
+ GsonBuilder
and invoke
+ GsonBuilder.setVersion(double)
method.
+
+
Here is an example of how this annotation is meant to be used:
++ public class User { + private String firstName; + private String lastName; + @Until(1.1) private String emailAddress; + @Until(1.1) private String password; + } ++ +
If you created Gson with new Gson()
, the toJson()
and fromJson()
+ methods will use all the fields for serialization and deserialization. However, if you created
+ Gson with Gson gson = new GsonBuilder().setVersion(1.2).create()
then the
+ toJson()
and fromJson()
methods of Gson will exclude the emailAddress
+ and password
fields from the example above, because the version number passed to the
+ GsonBuilder, 1.2
, exceeds the version number set on the Until
annotation,
+ 1.1
, for those fields.
+
+ +
+
+Required Element Summary | +|
---|---|
+ double |
+value
+
++ the value indicating a version number until this member + or type should be ignored. |
+
+Element Detail | +
---|
+public abstract double value+
+
+
+
|
++ + | +|||||||||
+ PREV CLASS + NEXT CLASS | ++ FRAMES + NO FRAMES + + + + + | +|||||||||
+ SUMMARY: REQUIRED | OPTIONAL | ++DETAIL: ELEMENT | +
+
+
|
++ + | +|||||||||
+ PREV + NEXT | ++ FRAMES + NO FRAMES + + + + + | +
+
+
+
|
++ + | +|||||||||
+ PREV + NEXT | ++ FRAMES + NO FRAMES + + + + + | +
+
+
|
++ + | +|||||||||
+ PREV + NEXT | ++ FRAMES + NO FRAMES + + + + + | +
+
+
+
|
++ + | +|||||||||
+ PREV + NEXT | ++ FRAMES + NO FRAMES + + + + + | +
+
+
|
++ + | +|||||||||
+ PREV + NEXT | ++ FRAMES + NO FRAMES + + + + + | +
+
+
+
|
++ + | +|||||||||
+ PREV + NEXT | ++ FRAMES + NO FRAMES + + + + + | +
+
+
|
++ + | +|||||||||
+ PREV + NEXT | ++ FRAMES + NO FRAMES + + + + + | +
+
+
+
|
++ + | +|||||||||
+ PREV + NEXT | ++ FRAMES + NO FRAMES + + + + + | +
+Annotation Types
+
+ +Expose + +SerializedName + +Since + +Until |
+
+
+
|
++ + | +|||||||||
+ PREV PACKAGE + NEXT PACKAGE | ++ FRAMES + NO FRAMES + + + + + | +
Gson
.
+
+See:
+
+ Description
+
+ +
+Annotation Types Summary | +|
---|---|
Expose | +An annotation that indicates this member should be exposed for JSON + serialization or deserialization. | +
SerializedName | +An annotation that indicates this member should be serialized to JSON with + the provided name value as its field name. | +
Since | +An annotation that indicates the version number since a member or a type has been present. | +
Until | +An annotation that indicates the version number until a member or a type should be present. | +
+This package provides annotations that can be used with Gson
.
+
+ +
+
+
+
|
++ + | +|||||||||
+ PREV PACKAGE + NEXT PACKAGE | ++ FRAMES + NO FRAMES + + + + + | +
+
+
|
++ + | +|||||||||
+ PREV + NEXT | ++ FRAMES + NO FRAMES + + + + + | +
+
+
|
++ + | +|||||||||
+ PREV + NEXT | ++ FRAMES + NO FRAMES + + + + + | +
+
+
|
++ + | +|||||||||
+ PREV + NEXT | ++ FRAMES + NO FRAMES + + + + + | +
+
+
+
|
++ + | +|||||||||
+ PREV + NEXT | ++ FRAMES + NO FRAMES + + + + + | +
+
+
|
++ + | +|||||||||
+ PREV + NEXT | ++ FRAMES + NO FRAMES + + + + + | +
+Packages that use ExclusionStrategy | +|
---|---|
com.google.gson | +This package provides the Gson class to convert Json to Java and
+ vice-versa. |
+
+Uses of ExclusionStrategy in com.google.gson | +
---|
+ +
Methods in com.google.gson with parameters of type ExclusionStrategy | +|
---|---|
+ GsonBuilder |
+GsonBuilder.setExclusionStrategies(ExclusionStrategy... strategies)
+
++ Configures Gson to apply a set of exclusion strategies during both serialization and + deserialization. |
+
+
+
+
|
++ + | +|||||||||
+ PREV + NEXT | ++ FRAMES + NO FRAMES + + + + + | +
+
+
|
++ + | +|||||||||
+ PREV + NEXT | ++ FRAMES + NO FRAMES + + + + + | +
+Packages that use FieldAttributes | +|
---|---|
com.google.gson | +This package provides the Gson class to convert Json to Java and
+ vice-versa. |
+
+Uses of FieldAttributes in com.google.gson | +
---|
+ +
Methods in com.google.gson with parameters of type FieldAttributes | +|
---|---|
+ boolean |
+ExclusionStrategy.shouldSkipField(FieldAttributes f)
+
++ |
+
+
+
+
|
++ + | +|||||||||
+ PREV + NEXT | ++ FRAMES + NO FRAMES + + + + + | +
+
+
|
++ + | +|||||||||
+ PREV + NEXT | ++ FRAMES + NO FRAMES + + + + + | +
+Packages that use FieldNamingPolicy | +|
---|---|
com.google.gson | +This package provides the Gson class to convert Json to Java and
+ vice-versa. |
+
+Uses of FieldNamingPolicy in com.google.gson | +
---|
+ +
Methods in com.google.gson that return FieldNamingPolicy | +|
---|---|
+static FieldNamingPolicy |
+FieldNamingPolicy.valueOf(String name)
+
++ Returns the enum constant of this type with the specified name. |
+
+static FieldNamingPolicy[] |
+FieldNamingPolicy.values()
+
++ Returns an array containing the constants of this enum type, in +the order they are declared. |
+
+ +
Methods in com.google.gson with parameters of type FieldNamingPolicy | +|
---|---|
+ GsonBuilder |
+GsonBuilder.setFieldNamingPolicy(FieldNamingPolicy namingConvention)
+
++ Configures Gson to apply a specific naming policy to an object's field during serialization + and deserialization. |
+
+
+
+
|
++ + | +|||||||||
+ PREV + NEXT | ++ FRAMES + NO FRAMES + + + + + | +
+
+
|
++ + | +|||||||||
+ PREV + NEXT | ++ FRAMES + NO FRAMES + + + + + | +
+Packages that use FieldNamingStrategy | +|
---|---|
com.google.gson | +This package provides the Gson class to convert Json to Java and
+ vice-versa. |
+
+Uses of FieldNamingStrategy in com.google.gson | +
---|
+ +
Methods in com.google.gson with parameters of type FieldNamingStrategy | +|
---|---|
+ GsonBuilder |
+GsonBuilder.setFieldNamingStrategy(FieldNamingStrategy fieldNamingStrategy)
+
++ Configures Gson to apply a specific naming policy strategy to an object's field during + serialization and deserialization. |
+
+
+
+
|
++ + | +|||||||||
+ PREV + NEXT | ++ FRAMES + NO FRAMES + + + + + | +
+
+
|
++ + | +|||||||||
+ PREV + NEXT | ++ FRAMES + NO FRAMES + + + + + | +
+Packages that use Gson | +|
---|---|
com.google.gson | +This package provides the Gson class to convert Json to Java and
+ vice-versa. |
+
+Uses of Gson in com.google.gson | +
---|
+ +
Methods in com.google.gson that return Gson | +|
---|---|
+ Gson |
+GsonBuilder.create()
+
++ Creates a Gson instance based on the current configuration. |
+
+
+
+
|
++ + | +|||||||||
+ PREV + NEXT | ++ FRAMES + NO FRAMES + + + + + | +
+
+
|
++ + | +|||||||||
+ PREV + NEXT | ++ FRAMES + NO FRAMES + + + + + | +
+Packages that use GsonBuilder | +|
---|---|
com.google.gson | +This package provides the Gson class to convert Json to Java and
+ vice-versa. |
+
+Uses of GsonBuilder in com.google.gson | +
---|
+ +
Methods in com.google.gson that return GsonBuilder | +|
---|---|
+ GsonBuilder |
+GsonBuilder.disableHtmlEscaping()
+
++ By default, Gson escapes HTML characters such as < > etc. |
+
+ GsonBuilder |
+GsonBuilder.disableInnerClassSerialization()
+
++ Configures Gson to exclude inner classes during serialization. |
+
+ GsonBuilder |
+GsonBuilder.excludeFieldsWithModifiers(int... modifiers)
+
++ Configures Gson to excludes all class fields that have the specified modifiers. |
+
+ GsonBuilder |
+GsonBuilder.excludeFieldsWithoutExposeAnnotation()
+
++ Configures Gson to exclude all fields from consideration for serialization or deserialization + that do not have the Expose annotation. |
+
+ GsonBuilder |
+GsonBuilder.generateNonExecutableJson()
+
++ Makes the output JSON non-executable in Javascript by prefixing the generated JSON with some + special text. |
+
+ GsonBuilder |
+GsonBuilder.registerTypeAdapter(Type type,
+ Object typeAdapter)
+
++ Configures Gson for custom serialization or deserialization. |
+
+ GsonBuilder |
+GsonBuilder.serializeNulls()
+
++ Configure Gson to serialize null fields. |
+
+ GsonBuilder |
+GsonBuilder.serializeSpecialFloatingPointValues()
+
++ Section 2.4 of JSON specification disallows + special double values (NaN, Infinity, -Infinity). |
+
+ GsonBuilder |
+GsonBuilder.setDateFormat(int style)
+
++ Configures Gson to to serialize Date objects according to the style value provided. |
+
+ GsonBuilder |
+GsonBuilder.setDateFormat(int dateStyle,
+ int timeStyle)
+
++ Configures Gson to to serialize Date objects according to the style value provided. |
+
+ GsonBuilder |
+GsonBuilder.setDateFormat(String pattern)
+
++ Configures Gson to serialize Date objects according to the pattern provided. |
+
+ GsonBuilder |
+GsonBuilder.setExclusionStrategies(ExclusionStrategy... strategies)
+
++ Configures Gson to apply a set of exclusion strategies during both serialization and + deserialization. |
+
+ GsonBuilder |
+GsonBuilder.setFieldNamingPolicy(FieldNamingPolicy namingConvention)
+
++ Configures Gson to apply a specific naming policy to an object's field during serialization + and deserialization. |
+
+ GsonBuilder |
+GsonBuilder.setFieldNamingStrategy(FieldNamingStrategy fieldNamingStrategy)
+
++ Configures Gson to apply a specific naming policy strategy to an object's field during + serialization and deserialization. |
+
+ GsonBuilder |
+GsonBuilder.setLongSerializationPolicy(LongSerializationPolicy serializationPolicy)
+
++ Configures Gson to apply a specific serialization policy for Long and long
+ objects. |
+
+ GsonBuilder |
+GsonBuilder.setPrettyPrinting()
+
++ Configures Gson to output Json that fits in a page for pretty printing. |
+
+ GsonBuilder |
+GsonBuilder.setVersion(double ignoreVersionsAfter)
+
++ Configures Gson to enable versioning support. |
+
+
+
+
|
++ + | +|||||||||
+ PREV + NEXT | ++ FRAMES + NO FRAMES + + + + + | +
+
+
|
++ + | +|||||||||
+ PREV + NEXT | ++ FRAMES + NO FRAMES + + + + + | +
+
+
+
|
++ + | +|||||||||
+ PREV + NEXT | ++ FRAMES + NO FRAMES + + + + + | +
+
+
|
++ + | +|||||||||
+ PREV + NEXT | ++ FRAMES + NO FRAMES + + + + + | +
+Packages that use JsonArray | +|
---|---|
com.google.gson | +This package provides the Gson class to convert Json to Java and
+ vice-versa. |
+
+Uses of JsonArray in com.google.gson | +
---|
+ +
Methods in com.google.gson that return JsonArray | +|
---|---|
+ JsonArray |
+JsonElement.getAsJsonArray()
+
++ convenience method to get this element as a JsonArray . |
+
+ JsonArray |
+JsonObject.getAsJsonArray(String memberName)
+
++ Convenience method to get the specified member as a JsonArray. |
+
+ +
Methods in com.google.gson with parameters of type JsonArray | +|
---|---|
+ void |
+JsonArray.addAll(JsonArray array)
+
++ Adds all the elements of the specified array to self. |
+
+
+
+
|
++ + | +|||||||||
+ PREV + NEXT | ++ FRAMES + NO FRAMES + + + + + | +
+
+
|
++ + | +|||||||||
+ PREV + NEXT | ++ FRAMES + NO FRAMES + + + + + | +
+Packages that use JsonDeserializationContext | +|
---|---|
com.google.gson | +This package provides the Gson class to convert Json to Java and
+ vice-versa. |
+
+Uses of JsonDeserializationContext in com.google.gson | +
---|
+ +
Methods in com.google.gson with parameters of type JsonDeserializationContext | +|
---|---|
+ T |
+JsonDeserializer.deserialize(JsonElement json,
+ Type typeOfT,
+ JsonDeserializationContext context)
+
++ Gson invokes this call-back method during deserialization when it encounters a field of the + specified type. |
+
+
+
+
|
++ + | +|||||||||
+ PREV + NEXT | ++ FRAMES + NO FRAMES + + + + + | +
+
+
|
++ + | +|||||||||
+ PREV + NEXT | ++ FRAMES + NO FRAMES + + + + + | +
+
+
+
|
++ + | +|||||||||
+ PREV + NEXT | ++ FRAMES + NO FRAMES + + + + + | +
+
+
|
++ + | +|||||||||
+ PREV + NEXT | ++ FRAMES + NO FRAMES + + + + + | +
+Packages that use JsonElement | +|
---|---|
com.google.gson | +This package provides the Gson class to convert Json to Java and
+ vice-versa. |
+
+Uses of JsonElement in com.google.gson | +
---|
+ +
Subclasses of JsonElement in com.google.gson | +|
---|---|
+ class |
+JsonArray
+
++ A class representing an array type in Json. |
+
+ class |
+JsonNull
+
++ A class representing a Json null value. |
+
+ class |
+JsonObject
+
++ A class representing an object type in Json. |
+
+ class |
+JsonPrimitive
+
++ A class representing a Json primitive value. |
+
+ +
Methods in com.google.gson that return JsonElement | +|
---|---|
+ JsonElement |
+JsonArray.get(int i)
+
++ Returns the ith element of the array. |
+
+ JsonElement |
+JsonObject.get(String memberName)
+
++ Returns the member with the specified name. |
+
+ JsonElement |
+JsonStreamParser.next()
+
++ Returns the next available JsonElement on the reader. |
+
+ JsonElement |
+JsonParser.parse(JsonReader json)
+
++ Returns the next value from the JSON stream as a parse tree. |
+
+ JsonElement |
+JsonParser.parse(Reader json)
+
++ Parses the specified JSON string into a parse tree |
+
+ JsonElement |
+JsonParser.parse(String json)
+
++ Parses the specified JSON string into a parse tree |
+
+ JsonElement |
+JsonObject.remove(String property)
+
++ Removes the property from this JsonObject . |
+
+ JsonElement |
+LongSerializationPolicy.serialize(Long value)
+
++ Serialize this value using this serialization policy. |
+
+ JsonElement |
+JsonSerializationContext.serialize(Object src)
+
++ Invokes default serialization on the specified object. |
+
+ JsonElement |
+JsonSerializationContext.serialize(Object src,
+ Type typeOfSrc)
+
++ Invokes default serialization on the specified object passing the specific type information. |
+
+ JsonElement |
+JsonSerializer.serialize(T src,
+ Type typeOfSrc,
+ JsonSerializationContext context)
+
++ Gson invokes this call-back method during serialization when it encounters a field of the + specified type. |
+
+ JsonElement |
+Gson.toJsonTree(Object src)
+
++ This method serializes the specified object into its equivalent representation as a tree of + JsonElement s. |
+
+ JsonElement |
+Gson.toJsonTree(Object src,
+ Type typeOfSrc)
+
++ This method serializes the specified object, including those of generic types, into its + equivalent representation as a tree of JsonElement s. |
+
+ +
Methods in com.google.gson that return types with arguments of type JsonElement | +|
---|---|
+ Set<Map.Entry<String,JsonElement>> |
+JsonObject.entrySet()
+
++ Returns a set of members of this object. |
+
+ Iterator<JsonElement> |
+JsonArray.iterator()
+
++ Returns an iterator to navigate the elemetns of the array. |
+
+ +
Methods in com.google.gson with parameters of type JsonElement | +||
---|---|---|
+ void |
+JsonArray.add(JsonElement element)
+
++ Adds the specified element to self. |
+|
+ void |
+JsonObject.add(String property,
+ JsonElement value)
+
++ Adds a member, which is a name-value pair, to self. |
+|
+
+ |
+JsonDeserializationContext.deserialize(JsonElement json,
+ Type typeOfT)
+
++ Invokes default deserialization on the specified object. |
+|
+ T |
+JsonDeserializer.deserialize(JsonElement json,
+ Type typeOfT,
+ JsonDeserializationContext context)
+
++ Gson invokes this call-back method during deserialization when it encounters a field of the + specified type. |
+|
+
+ |
+Gson.fromJson(JsonElement json,
+ Class<T> classOfT)
+
++ This method deserializes the Json read from the specified parse tree into an object of the + specified type. |
+|
+
+ |
+Gson.fromJson(JsonElement json,
+ Type typeOfT)
+
++ This method deserializes the Json read from the specified parse tree into an object of the + specified type. |
+|
+ String |
+Gson.toJson(JsonElement jsonElement)
+
++ Converts a tree of JsonElement s into its equivalent JSON representation. |
+|
+ void |
+Gson.toJson(JsonElement jsonElement,
+ Appendable writer)
+
++ Writes out the equivalent JSON for a tree of JsonElement s. |
+|
+ void |
+Gson.toJson(JsonElement jsonElement,
+ JsonWriter writer)
+
++ Writes the JSON for jsonElement to writer . |
+
+
+
+
|
++ + | +|||||||||
+ PREV + NEXT | ++ FRAMES + NO FRAMES + + + + + | +
+
+
|
++ + | +|||||||||
+ PREV + NEXT | ++ FRAMES + NO FRAMES + + + + + | +
+Packages that use JsonIOException | +|
---|---|
com.google.gson | +This package provides the Gson class to convert Json to Java and
+ vice-versa. |
+
+Uses of JsonIOException in com.google.gson | +
---|
+ +
Methods in com.google.gson that throw JsonIOException | +||
---|---|---|
+
+ |
+Gson.fromJson(JsonReader reader,
+ Type typeOfT)
+
++ Reads the next JSON value from reader and convert it to an object
+ of type typeOfT . |
+|
+
+ |
+Gson.fromJson(Reader json,
+ Class<T> classOfT)
+
++ This method deserializes the Json read from the specified reader into an object of the + specified class. |
+|
+
+ |
+Gson.fromJson(Reader json,
+ Type typeOfT)
+
++ This method deserializes the Json read from the specified reader into an object of the + specified type. |
+|
+ JsonElement |
+JsonParser.parse(JsonReader json)
+
++ Returns the next value from the JSON stream as a parse tree. |
+|
+ JsonElement |
+JsonParser.parse(Reader json)
+
++ Parses the specified JSON string into a parse tree |
+|
+ void |
+Gson.toJson(JsonElement jsonElement,
+ Appendable writer)
+
++ Writes out the equivalent JSON for a tree of JsonElement s. |
+|
+ void |
+Gson.toJson(JsonElement jsonElement,
+ JsonWriter writer)
+
++ Writes the JSON for jsonElement to writer . |
+|
+ void |
+Gson.toJson(Object src,
+ Appendable writer)
+
++ This method serializes the specified object into its equivalent Json representation. |
+|
+ void |
+Gson.toJson(Object src,
+ Type typeOfSrc,
+ Appendable writer)
+
++ This method serializes the specified object, including those of generic types, into its + equivalent Json representation. |
+|
+ void |
+Gson.toJson(Object src,
+ Type typeOfSrc,
+ JsonWriter writer)
+
++ Writes the JSON representation of src of type typeOfSrc to
+ writer . |
+
+
+
+
|
++ + | +|||||||||
+ PREV + NEXT | ++ FRAMES + NO FRAMES + + + + + | +
+
+
|
++ + | +|||||||||
+ PREV + NEXT | ++ FRAMES + NO FRAMES + + + + + | +
+Packages that use JsonNull | +|
---|---|
com.google.gson | +This package provides the Gson class to convert Json to Java and
+ vice-versa. |
+
+Uses of JsonNull in com.google.gson | +
---|
+ +
Methods in com.google.gson that return JsonNull | +|
---|---|
+ JsonNull |
+JsonElement.getAsJsonNull()
+
++ convenience method to get this element as a JsonNull . |
+
+
+
+
|
++ + | +|||||||||
+ PREV + NEXT | ++ FRAMES + NO FRAMES + + + + + | +
+
+
|
++ + | +|||||||||
+ PREV + NEXT | ++ FRAMES + NO FRAMES + + + + + | +
+Packages that use JsonObject | +|
---|---|
com.google.gson | +This package provides the Gson class to convert Json to Java and
+ vice-versa. |
+
+Uses of JsonObject in com.google.gson | +
---|
+ +
Methods in com.google.gson that return JsonObject | +|
---|---|
+ JsonObject |
+JsonElement.getAsJsonObject()
+
++ convenience method to get this element as a JsonObject . |
+
+ JsonObject |
+JsonObject.getAsJsonObject(String memberName)
+
++ Convenience method to get the specified member as a JsonObject. |
+
+
+
+
|
++ + | +|||||||||
+ PREV + NEXT | ++ FRAMES + NO FRAMES + + + + + | +
+
+
|
++ + | +|||||||||
+ PREV + NEXT | ++ FRAMES + NO FRAMES + + + + + | +
+Packages that use JsonParseException | +|
---|---|
com.google.gson | +This package provides the Gson class to convert Json to Java and
+ vice-versa. |
+
+Uses of JsonParseException in com.google.gson | +
---|
+ +
Subclasses of JsonParseException in com.google.gson | +|
---|---|
+ class |
+JsonIOException
+
++ This exception is raised when Gson was unable to read an input stream + or write to one. |
+
+ class |
+JsonSyntaxException
+
++ This exception is raised when Gson attempts to read (or write) a malformed + JSON element. |
+
+ +
Methods in com.google.gson that throw JsonParseException | +||
---|---|---|
+
+ |
+JsonDeserializationContext.deserialize(JsonElement json,
+ Type typeOfT)
+
++ Invokes default deserialization on the specified object. |
+|
+ T |
+JsonDeserializer.deserialize(JsonElement json,
+ Type typeOfT,
+ JsonDeserializationContext context)
+
++ Gson invokes this call-back method during deserialization when it encounters a field of the + specified type. |
+|
+ JsonElement |
+JsonStreamParser.next()
+
++ Returns the next available JsonElement on the reader. |
+
+
+
+
|
++ + | +|||||||||
+ PREV + NEXT | ++ FRAMES + NO FRAMES + + + + + | +
+
+
|
++ + | +|||||||||
+ PREV + NEXT | ++ FRAMES + NO FRAMES + + + + + | +
+
+
+
|
++ + | +|||||||||
+ PREV + NEXT | ++ FRAMES + NO FRAMES + + + + + | +
+
+
|
++ + | +|||||||||
+ PREV + NEXT | ++ FRAMES + NO FRAMES + + + + + | +
+Packages that use JsonPrimitive | +|
---|---|
com.google.gson | +This package provides the Gson class to convert Json to Java and
+ vice-versa. |
+
+Uses of JsonPrimitive in com.google.gson | +
---|
+ +
Methods in com.google.gson that return JsonPrimitive | +|
---|---|
+ JsonPrimitive |
+JsonElement.getAsJsonPrimitive()
+
++ convenience method to get this element as a JsonPrimitive . |
+
+ JsonPrimitive |
+JsonObject.getAsJsonPrimitive(String memberName)
+
++ Convenience method to get the specified member as a JsonPrimitive element. |
+
+
+
+
|
++ + | +|||||||||
+ PREV + NEXT | ++ FRAMES + NO FRAMES + + + + + | +
+
+
|
++ + | +|||||||||
+ PREV + NEXT | ++ FRAMES + NO FRAMES + + + + + | +
+Packages that use JsonSerializationContext | +|
---|---|
com.google.gson | +This package provides the Gson class to convert Json to Java and
+ vice-versa. |
+
+Uses of JsonSerializationContext in com.google.gson | +
---|
+ +
Methods in com.google.gson with parameters of type JsonSerializationContext | +|
---|---|
+ JsonElement |
+JsonSerializer.serialize(T src,
+ Type typeOfSrc,
+ JsonSerializationContext context)
+
++ Gson invokes this call-back method during serialization when it encounters a field of the + specified type. |
+
+
+
+
|
++ + | +|||||||||
+ PREV + NEXT | ++ FRAMES + NO FRAMES + + + + + | +
+
+
|
++ + | +|||||||||
+ PREV + NEXT | ++ FRAMES + NO FRAMES + + + + + | +
+
+
+
|
++ + | +|||||||||
+ PREV + NEXT | ++ FRAMES + NO FRAMES + + + + + | +
+
+
|
++ + | +|||||||||
+ PREV + NEXT | ++ FRAMES + NO FRAMES + + + + + | +
+
+
+
|
++ + | +|||||||||
+ PREV + NEXT | ++ FRAMES + NO FRAMES + + + + + | +
+
+
|
++ + | +|||||||||
+ PREV + NEXT | ++ FRAMES + NO FRAMES + + + + + | +
+Packages that use JsonSyntaxException | +|
---|---|
com.google.gson | +This package provides the Gson class to convert Json to Java and
+ vice-versa. |
+
+Uses of JsonSyntaxException in com.google.gson | +
---|
+ +
Methods in com.google.gson that throw JsonSyntaxException | +||
---|---|---|
+
+ |
+Gson.fromJson(JsonElement json,
+ Class<T> classOfT)
+
++ This method deserializes the Json read from the specified parse tree into an object of the + specified type. |
+|
+
+ |
+Gson.fromJson(JsonElement json,
+ Type typeOfT)
+
++ This method deserializes the Json read from the specified parse tree into an object of the + specified type. |
+|
+
+ |
+Gson.fromJson(JsonReader reader,
+ Type typeOfT)
+
++ Reads the next JSON value from reader and convert it to an object
+ of type typeOfT . |
+|
+
+ |
+Gson.fromJson(Reader json,
+ Class<T> classOfT)
+
++ This method deserializes the Json read from the specified reader into an object of the + specified class. |
+|
+
+ |
+Gson.fromJson(Reader json,
+ Type typeOfT)
+
++ This method deserializes the Json read from the specified reader into an object of the + specified type. |
+|
+
+ |
+Gson.fromJson(String json,
+ Class<T> classOfT)
+
++ This method deserializes the specified Json into an object of the specified class. |
+|
+
+ |
+Gson.fromJson(String json,
+ Type typeOfT)
+
++ This method deserializes the specified Json into an object of the specified type. |
+|
+ JsonElement |
+JsonParser.parse(JsonReader json)
+
++ Returns the next value from the JSON stream as a parse tree. |
+|
+ JsonElement |
+JsonParser.parse(Reader json)
+
++ Parses the specified JSON string into a parse tree |
+|
+ JsonElement |
+JsonParser.parse(String json)
+
++ Parses the specified JSON string into a parse tree |
+
+
+
+
|
++ + | +|||||||||
+ PREV + NEXT | ++ FRAMES + NO FRAMES + + + + + | +
+
+
|
++ + | +|||||||||
+ PREV + NEXT | ++ FRAMES + NO FRAMES + + + + + | +
+Packages that use LongSerializationPolicy | +|
---|---|
com.google.gson | +This package provides the Gson class to convert Json to Java and
+ vice-versa. |
+
+Uses of LongSerializationPolicy in com.google.gson | +
---|
+ +
Methods in com.google.gson that return LongSerializationPolicy | +|
---|---|
+static LongSerializationPolicy |
+LongSerializationPolicy.valueOf(String name)
+
++ Returns the enum constant of this type with the specified name. |
+
+static LongSerializationPolicy[] |
+LongSerializationPolicy.values()
+
++ Returns an array containing the constants of this enum type, in +the order they are declared. |
+
+ +
Methods in com.google.gson with parameters of type LongSerializationPolicy | +|
---|---|
+ GsonBuilder |
+GsonBuilder.setLongSerializationPolicy(LongSerializationPolicy serializationPolicy)
+
++ Configures Gson to apply a specific serialization policy for Long and long
+ objects. |
+
+
+
+
|
++ + | +|||||||||
+ PREV + NEXT | ++ FRAMES + NO FRAMES + + + + + | +
+Interfaces
+
+ +ExclusionStrategy + +FieldNamingStrategy + +InstanceCreator + +JsonDeserializationContext + +JsonDeserializer + +JsonSerializationContext + +JsonSerializer |
+
+Classes
+
+ +FieldAttributes + +Gson + +GsonBuilder + +JsonArray + +JsonElement + +JsonNull + +JsonObject + +JsonParser + +JsonPrimitive + +JsonStreamParser |
+
+Enums
+
+ +FieldNamingPolicy + +LongSerializationPolicy |
+
+Exceptions
+
+ +JsonIOException + +JsonParseException + +JsonSyntaxException |
+
+
+
|
++ + | +|||||||||
+ PREV PACKAGE + NEXT PACKAGE | ++ FRAMES + NO FRAMES + + + + + | +
Gson
class to convert Json to Java and
+ vice-versa.
+
+See:
+
+ Description
+
+ +
+Interface Summary | +|
---|---|
ExclusionStrategy | +A strategy (or policy) definition that is used to decide whether or not a field or top-level + class should be serialized or deserialized as part of the JSON output/input. | +
FieldNamingStrategy | +A mechanism for providing custom field naming in Gson. | +
InstanceCreator<T> | +This interface is implemented to create instances of a class that does not define a no-args + constructor. | +
JsonDeserializationContext | +Context for deserialization that is passed to a custom deserializer during invocation of its
+ JsonDeserializer.deserialize(JsonElement, Type, JsonDeserializationContext)
+ method. |
+
JsonDeserializer<T> | +Interface representing a custom deserializer for Json. | +
JsonSerializationContext | +Context for serialization that is passed to a custom serializer during invocation of its
+ JsonSerializer.serialize(Object, Type, JsonSerializationContext) method. |
+
JsonSerializer<T> | +Interface representing a custom serializer for Json. | +
+ +
+Class Summary | +|
---|---|
FieldAttributes | +A data object that stores attributes of a field. | +
Gson | +This is the main class for using Gson. | +
GsonBuilder | +Use this builder to construct a Gson instance when you need to set configuration
+ options other than the default. |
+
JsonArray | +A class representing an array type in Json. | +
JsonElement | +A class representing an element of Json. | +
JsonNull | +A class representing a Json null value. |
+
JsonObject | +A class representing an object type in Json. | +
JsonParser | +A parser to parse Json into a parse tree of JsonElement s |
+
JsonPrimitive | +A class representing a Json primitive value. | +
JsonStreamParser | +A streaming parser that allows reading of multiple JsonElement s from the specified reader
+ asynchronously. |
+
+ +
+Enum Summary | +|
---|---|
FieldNamingPolicy | +An enumeration that defines a few standard naming conventions for JSON field names. | +
LongSerializationPolicy | +Defines the expected format for a long or Long type when its serialized. |
+
+ +
+Exception Summary | +|
---|---|
JsonIOException | +This exception is raised when Gson was unable to read an input stream + or write to one. | +
JsonParseException | +This exception is raised if there is a serious issue that occurs during parsing of a Json + string. | +
JsonSyntaxException | +This exception is raised when Gson attempts to read (or write) a malformed + JSON element. | +
+This package provides the Gson
class to convert Json to Java and
+ vice-versa.
+
+
The primary class to use is Gson
which can be constructed with
+ new Gson()
(using default settings) or by using GsonBuilder
+ (to configure various options such as using versioning and so on).
+ +
+
+
+
|
++ + | +|||||||||
+ PREV PACKAGE + NEXT PACKAGE | ++ FRAMES + NO FRAMES + + + + + | +
+
+
|
++ + | +|||||||||
+ PREV + NEXT | ++ FRAMES + NO FRAMES + + + + + | +
+
+
|
++ + | +|||||||||
+ PREV + NEXT | ++ FRAMES + NO FRAMES + + + + + | +
+
+
|
++ + | +|||||||||
+ PREV + NEXT | ++ FRAMES + NO FRAMES + + + + + | +
+Packages that use com.google.gson | +|
---|---|
com.google.gson | +This package provides the Gson class to convert Json to Java and
+ vice-versa. |
+
+Classes in com.google.gson used by com.google.gson | +|
---|---|
ExclusionStrategy
+
+ + A strategy (or policy) definition that is used to decide whether or not a field or top-level + class should be serialized or deserialized as part of the JSON output/input. |
+|
FieldAttributes
+
+ + A data object that stores attributes of a field. |
+|
FieldNamingPolicy
+
+ + An enumeration that defines a few standard naming conventions for JSON field names. |
+|
FieldNamingStrategy
+
+ + A mechanism for providing custom field naming in Gson. |
+|
Gson
+
+ + This is the main class for using Gson. |
+|
GsonBuilder
+
+ + Use this builder to construct a Gson instance when you need to set configuration
+ options other than the default. |
+|
JsonArray
+
+ + A class representing an array type in Json. |
+|
JsonDeserializationContext
+
+ + Context for deserialization that is passed to a custom deserializer during invocation of its + JsonDeserializer.deserialize(JsonElement, Type, JsonDeserializationContext)
+ method. |
+|
JsonElement
+
+ + A class representing an element of Json. |
+|
JsonIOException
+
+ + This exception is raised when Gson was unable to read an input stream + or write to one. |
+|
JsonNull
+
+ + A class representing a Json null value. |
+|
JsonObject
+
+ + A class representing an object type in Json. |
+|
JsonParseException
+
+ + This exception is raised if there is a serious issue that occurs during parsing of a Json + string. |
+|
JsonPrimitive
+
+ + A class representing a Json primitive value. |
+|
JsonSerializationContext
+
+ + Context for serialization that is passed to a custom serializer during invocation of its + JsonSerializer.serialize(Object, Type, JsonSerializationContext) method. |
+|
JsonSyntaxException
+
+ + This exception is raised when Gson attempts to read (or write) a malformed + JSON element. |
+|
LongSerializationPolicy
+
+ + Defines the expected format for a long or Long type when its serialized. |
+
+
+
+
|
++ + | +|||||||||
+ PREV + NEXT | ++ FRAMES + NO FRAMES + + + + + | +
+
+
|
++ + | +|||||||||
+ PREV CLASS + NEXT CLASS | ++ FRAMES + NO FRAMES + + + + + | +|||||||||
+ SUMMARY: NESTED | FIELD | CONSTR | METHOD | ++DETAIL: FIELD | CONSTR | METHOD | +
+java.lang.Object + com.google.gson.reflect.TypeToken<T> ++
public abstract class TypeToken<T>
+Represents a generic type T
.
+
+ You can use this class to get the generic type for a class. For example,
+ to get the generic type for Collection<Foo>
, you can use:
+
+ Type typeOfCollectionOfFoo = new TypeToken<Collection<Foo>>(){}.getType()
+
+
+
Assumes Type
implements equals()
and hashCode()
+ as a value (as opposed to identity) comparison.
+
+ Also implements isAssignableFrom(Type)
to check type-safe
+ assignability.
+
+ +
+
+Method Summary | +||
---|---|---|
+ boolean |
+equals(Object o)
+
++ Method to test equality. |
+|
+static
+ |
+get(Class<T> type)
+
++ Gets type token for the given Class instance. |
+|
+static TypeToken<?> |
+get(Type type)
+
++ Gets type token for the given Type instance. |
+|
+ Class<? super T> |
+getRawType()
+
++ Gets the raw type. |
+|
+ Type |
+getType()
+
++ Gets underlying Type instance. |
+|
+ int |
+hashCode()
+
++ Hashcode for this object. |
+|
+ boolean |
+isAssignableFrom(Class<?> cls)
+
++ Check if this type is assignable from the given class object. |
+|
+ boolean |
+isAssignableFrom(Type from)
+
++ Check if this type is assignable from the given Type. |
+|
+ boolean |
+isAssignableFrom(TypeToken<?> token)
+
++ Check if this type is assignable from the given type token. |
+|
+ String |
+toString()
+
++ Returns a string representation of this object. |
+
Methods inherited from class java.lang.Object | +
---|
getClass, notify, notifyAll, wait, wait, wait |
+
+Method Detail | +
---|
+public Class<? super T> getRawType()+
+
+public Type getType()+
Type
instance.
++
+public boolean isAssignableFrom(Class<?> cls)+
+
+public boolean isAssignableFrom(Type from)+
+
+public boolean isAssignableFrom(TypeToken<?> token)+
+
+public int hashCode()+
+
hashCode
in class Object
+public boolean equals(Object o)+
+
equals
in class Object
+public String toString()+
+
toString
in class Object
+public static TypeToken<?> get(Type type)+
Type
instance.
++
+public static <T> TypeToken<T> get(Class<T> type)+
Class
instance.
++
+
+
|
++ + | +|||||||||
+ PREV CLASS + NEXT CLASS | ++ FRAMES + NO FRAMES + + + + + | +|||||||||
+ SUMMARY: NESTED | FIELD | CONSTR | METHOD | ++DETAIL: FIELD | CONSTR | METHOD | +
+
+
|
++ + | +|||||||||
+ PREV + NEXT | ++ FRAMES + NO FRAMES + + + + + | +
+Packages that use TypeToken | +|
---|---|
com.google.gson.reflect | +This package provides utility classes for finding type information for generic types. | +
+Uses of TypeToken in com.google.gson.reflect | +
---|
+ +
Methods in com.google.gson.reflect that return TypeToken | +||
---|---|---|
+static
+ |
+TypeToken.get(Class<T> type)
+
++ Gets type token for the given Class instance. |
+|
+static TypeToken<?> |
+TypeToken.get(Type type)
+
++ Gets type token for the given Type instance. |
+
+ +
Methods in com.google.gson.reflect with parameters of type TypeToken | +|
---|---|
+ boolean |
+TypeToken.isAssignableFrom(TypeToken<?> token)
+
++ Check if this type is assignable from the given type token. |
+
+
+
+
|
++ + | +|||||||||
+ PREV + NEXT | ++ FRAMES + NO FRAMES + + + + + | +
+Classes
+
+ +TypeToken |
+
+
+
|
++ + | +|||||||||
+ PREV PACKAGE + NEXT PACKAGE | ++ FRAMES + NO FRAMES + + + + + | +
+See:
+
+ Description
+
+ +
+Class Summary | +|
---|---|
TypeToken<T> | +Represents a generic type T . |
+
+This package provides utility classes for finding type information for generic types. +
+ +
+
+
+
|
++ + | +|||||||||
+ PREV PACKAGE + NEXT PACKAGE | ++ FRAMES + NO FRAMES + + + + + | +
+
+
|
++ + | +|||||||||
+ PREV + NEXT | ++ FRAMES + NO FRAMES + + + + + | +
+
+
|
++ + | +|||||||||
+ PREV + NEXT | ++ FRAMES + NO FRAMES + + + + + | +
+
+
|
++ + | +|||||||||
+ PREV + NEXT | ++ FRAMES + NO FRAMES + + + + + | +
+Packages that use com.google.gson.reflect | +|
---|---|
com.google.gson.reflect | +This package provides utility classes for finding type information for generic types. | +
+Classes in com.google.gson.reflect used by com.google.gson.reflect | +|
---|---|
TypeToken
+
+ + Represents a generic type T . |
+
+
+
+
|
++ + | +|||||||||
+ PREV + NEXT | ++ FRAMES + NO FRAMES + + + + + | +
+
+
|
++ + | +|||||||||
+ PREV CLASS + NEXT CLASS | ++ FRAMES + NO FRAMES + + + + + | +|||||||||
+ SUMMARY: NESTED | FIELD | CONSTR | METHOD | ++DETAIL: FIELD | CONSTR | METHOD | +
+java.lang.Object + com.google.gson.stream.JsonReader ++
public final class JsonReader
+Reads a JSON (RFC 4627) + encoded value as a stream of tokens. This stream includes both literal + values (strings, numbers, booleans, and nulls) as well as the begin and + end delimiters of objects and arrays. The tokens are traversed in + depth-first order, the same order that they appear in the JSON document. + Within JSON objects, name/value pairs are represented by a single token. + +
JsonReader
.
+
+ Next, create handler methods for each structure in your JSON text. You'll + need a method for each object type and for each array type. +
beginArray()
to consume the array's opening bracket. Then create a
+ while loop that accumulates values, terminating when hasNext()
+ is false. Finally, read the array's closing bracket by calling endArray()
.
+ beginObject()
to consume the object's opening brace. Then create a
+ while loop that assigns values to local variables based on their name.
+ This loop should terminate when hasNext()
is false. Finally,
+ read the object's closing brace by calling endObject()
.
+ When a nested object or array is encountered, delegate to the + corresponding handler method. + +
When an unknown name is encountered, strict parsers should fail with an
+ exception. Lenient parsers should call skipValue()
to recursively
+ skip the value's nested tokens, which may otherwise conflict.
+
+
If a value may be null, you should first check using peek()
.
+ Null literals can be consumed using either nextNull()
or skipValue()
.
+
+
[
+ {
+ "id": 912345678901,
+ "text": "How do I read a JSON stream in Java?",
+ "geo": null,
+ "user": {
+ "name": "json_newb",
+ "followers_count": 41
+ }
+ },
+ {
+ "id": 912345678902,
+ "text": "@json_newb just use JsonReader!",
+ "geo": [50.454722, -104.606667],
+ "user": {
+ "name": "jesse",
+ "followers_count": 2
+ }
+ }
+ ]
+ This code implements the parser for the above structure: public List<Message> readJsonStream(InputStream in) throws IOException {
+ JsonReader reader = new JsonReader(new InputStreamReader(in, "UTF-8"));
+ return readMessagesArray(reader);
+ }
+
+ public List<Message> readMessagesArray(JsonReader reader) throws IOException {
+ List<Message> messages = new ArrayList<Message>();
+
+ reader.beginArray();
+ while (reader.hasNext()) {
+ messages.add(readMessage(reader));
+ }
+ reader.endArray();
+ return messages;
+ }
+
+ public Message readMessage(JsonReader reader) throws IOException {
+ long id = -1;
+ String text = null;
+ User user = null;
+ List<Double> geo = null;
+
+ reader.beginObject();
+ while (reader.hasNext()) {
+ String name = reader.nextName();
+ if (name.equals("id")) {
+ id = reader.nextLong();
+ } else if (name.equals("text")) {
+ text = reader.nextString();
+ } else if (name.equals("geo") && reader.peek() != JsonToken.NULL) {
+ geo = readDoublesArray(reader);
+ } else if (name.equals("user")) {
+ user = readUser(reader);
+ } else {
+ reader.skipValue();
+ }
+ }
+ reader.endObject();
+ return new Message(id, text, user, geo);
+ }
+
+ public List<Double> readDoublesArray(JsonReader reader) throws IOException {
+ List<Double> doubles = new ArrayList<Double>();
+
+ reader.beginArray();
+ while (reader.hasNext()) {
+ doubles.add(reader.nextDouble());
+ }
+ reader.endArray();
+ return doubles;
+ }
+
+ public User readUser(JsonReader reader) throws IOException {
+ String username = null;
+ int followersCount = -1;
+
+ reader.beginObject();
+ while (reader.hasNext()) {
+ String name = reader.nextName();
+ if (name.equals("name")) {
+ username = reader.nextString();
+ } else if (name.equals("followers_count")) {
+ followersCount = reader.nextInt();
+ } else {
+ reader.skipValue();
+ }
+ }
+ reader.endObject();
+ return new User(username, followersCount);
+ }
+
+ [1, "1"]
may be read using either nextInt()
or nextString()
.
+ This behavior is intended to prevent lossy numeric conversions: double is
+ JavaScript's only numeric type and very large values like 9007199254740993
cannot be represented exactly on that platform. To minimize
+ precision loss, extremely large values should be written and read as strings
+ in JSON.
+
+ <script>
tag.
+
+ Prefixing JSON files with ")]}'\n"
makes them non-executable
+ by <script>
tags, disarming the attack. Since the prefix is malformed
+ JSON, strict parsing fails when it is encountered. This class permits the
+ non-execute prefix when lenient parsing
is
+ enabled.
+
+
Each JsonReader
may be used to read a single JSON stream. Instances
+ of this class are not thread safe.
+
+ +
+
+Constructor Summary | +|
---|---|
JsonReader(Reader in)
+
++ Creates a new instance that reads a JSON-encoded stream from in . |
+
+Method Summary | +|
---|---|
+ void |
+beginArray()
+
++ Consumes the next token from the JSON stream and asserts that it is the + beginning of a new array. |
+
+ void |
+beginObject()
+
++ Consumes the next token from the JSON stream and asserts that it is the + beginning of a new object. |
+
+ void |
+close()
+
++ Closes this JSON reader and the underlying Reader . |
+
+ void |
+endArray()
+
++ Consumes the next token from the JSON stream and asserts that it is the + end of the current array. |
+
+ void |
+endObject()
+
++ Consumes the next token from the JSON stream and asserts that it is the + end of the current array. |
+
+ boolean |
+hasNext()
+
++ Returns true if the current array or object has another element. |
+
+ boolean |
+isLenient()
+
++ Returns true if this parser is liberal in what it accepts. |
+
+ boolean |
+nextBoolean()
+
++ Returns the boolean value of the next token,
+ consuming it. |
+
+ double |
+nextDouble()
+
++ Returns the double value of the next token,
+ consuming it. |
+
+ int |
+nextInt()
+
++ Returns the int value of the next token,
+ consuming it. |
+
+ long |
+nextLong()
+
++ Returns the long value of the next token,
+ consuming it. |
+
+ String |
+nextName()
+
++ Returns the next token, a property name , and
+ consumes it. |
+
+ void |
+nextNull()
+
++ Consumes the next token from the JSON stream and asserts that it is a + literal null. |
+
+ String |
+nextString()
+
++ Returns the string value of the next token,
+ consuming it. |
+
+ JsonToken |
+peek()
+
++ Returns the type of the next token without consuming it. |
+
+ void |
+setLenient(boolean lenient)
+
++ Configure this parser to be be liberal in what it accepts. |
+
+ void |
+skipValue()
+
++ Skips the next value recursively. |
+
+ String |
+toString()
+
++ |
+
Methods inherited from class java.lang.Object | +
---|
equals, getClass, hashCode, notify, notifyAll, wait, wait, wait |
+
+Constructor Detail | +
---|
+public JsonReader(Reader in)+
in
.
++
+Method Detail | +
---|
+public void setLenient(boolean lenient)+
")]}'\n"
.
+ NaNs
or infinities
.
+ //
or #
and
+ ending with a newline character.
+ /*
and ending with
+ *
/
. Such comments may not be nested.
+ 'single quoted'
.
+ 'single quoted'
.
+ ;
instead of ,
.
+ =
or =>
instead of
+ :
.
+ ;
instead of ,
.
+ +
+public boolean isLenient()+
+
+public void beginArray() + throws IOException+
+
IOException
+public void endArray() + throws IOException+
+
IOException
+public void beginObject() + throws IOException+
+
IOException
+public void endObject() + throws IOException+
+
IOException
+public boolean hasNext() + throws IOException+
+
IOException
+public JsonToken peek() + throws IOException+
+
IOException
+public String nextName() + throws IOException+
property name
, and
+ consumes it.
++
IOException
- if the next token in the stream is not a property
+ name.+public String nextString() + throws IOException+
string
value of the next token,
+ consuming it. If the next token is a number, this method will return its
+ string form.
++
IllegalStateException
- if the next token is not a string or if
+ this reader is closed.
+IOException
+public boolean nextBoolean() + throws IOException+
boolean
value of the next token,
+ consuming it.
++
IllegalStateException
- if the next token is not a boolean or if
+ this reader is closed.
+IOException
+public void nextNull() + throws IOException+
+
IllegalStateException
- if the next token is not null or if this
+ reader is closed.
+IOException
+public double nextDouble() + throws IOException+
double
value of the next token,
+ consuming it. If the next token is a string, this method will attempt to
+ parse it as a double.
++
IllegalStateException
- if the next token is not a literal value.
+NumberFormatException
- if the next literal value cannot be parsed
+ as a double, or is non-finite.
+IOException
+public long nextLong() + throws IOException+
long
value of the next token,
+ consuming it. If the next token is a string, this method will attempt to
+ parse it as a long. If the next token's numeric value cannot be exactly
+ represented by a Java long
, this method throws.
++
IllegalStateException
- if the next token is not a literal value.
+NumberFormatException
- if the next literal value cannot be parsed
+ as a number, or exactly represented as a long.
+IOException
+public int nextInt() + throws IOException+
int
value of the next token,
+ consuming it. If the next token is a string, this method will attempt to
+ parse it as an int. If the next token's numeric value cannot be exactly
+ represented by a Java int
, this method throws.
++
IllegalStateException
- if the next token is not a literal value.
+NumberFormatException
- if the next literal value cannot be parsed
+ as a number, or exactly represented as an int.
+IOException
+public void close() + throws IOException+
Reader
.
++
close
in interface Closeable
IOException
+public void skipValue() + throws IOException+
+
IOException
+public String toString()+
toString
in class Object
+
+
|
++ + | +|||||||||
+ PREV CLASS + NEXT CLASS | ++ FRAMES + NO FRAMES + + + + + | +|||||||||
+ SUMMARY: NESTED | FIELD | CONSTR | METHOD | ++DETAIL: FIELD | CONSTR | METHOD | +
+
+
|
++ + | +|||||||||
+ PREV CLASS + NEXT CLASS | ++ FRAMES + NO FRAMES + + + + + | +|||||||||
+ SUMMARY: NESTED | ENUM CONSTANTS | FIELD | METHOD | ++DETAIL: ENUM CONSTANTS | FIELD | METHOD | +
+java.lang.Object + java.lang.Enum<JsonToken> + com.google.gson.stream.JsonToken ++
public enum JsonToken
+A structure, name or value type in a JSON-encoded string. +
+ +
+
+Enum Constant Summary | +|
---|---|
BEGIN_ARRAY
+
++ The opening of a JSON array. |
+|
BEGIN_OBJECT
+
++ The opening of a JSON object. |
+|
BOOLEAN
+
++ A JSON true or false . |
+|
END_ARRAY
+
++ The closing of a JSON array. |
+|
END_DOCUMENT
+
++ The end of the JSON stream. |
+|
END_OBJECT
+
++ The closing of a JSON object. |
+|
NAME
+
++ A JSON property name. |
+|
NULL
+
++ A JSON null . |
+|
NUMBER
+
++ A JSON number represented in this API by a Java double , long , or int . |
+|
STRING
+
++ A JSON string. |
+
+Method Summary | +|
---|---|
+static JsonToken |
+valueOf(String name)
+
++ Returns the enum constant of this type with the specified name. |
+
+static JsonToken[] |
+values()
+
++ Returns an array containing the constants of this enum type, in +the order they are declared. |
+
Methods inherited from class java.lang.Enum | +
---|
compareTo, equals, getDeclaringClass, hashCode, name, ordinal, toString, valueOf |
+
Methods inherited from class java.lang.Object | +
---|
getClass, notify, notifyAll, wait, wait, wait |
+
+Enum Constant Detail | +
---|
+public static final JsonToken BEGIN_ARRAY+
JsonWriter.beginObject()
+ and read using JsonReader.beginObject()
.
++
+public static final JsonToken END_ARRAY+
JsonWriter.endArray()
+ and read using JsonReader.endArray()
.
++
+public static final JsonToken BEGIN_OBJECT+
JsonWriter.beginObject()
+ and read using JsonReader.beginObject()
.
++
+public static final JsonToken END_OBJECT+
JsonWriter.endObject()
+ and read using JsonReader.endObject()
.
++
+public static final JsonToken NAME+
JsonWriter.name(java.lang.String)
and read using JsonReader.nextName()
++
+public static final JsonToken STRING+
+
+public static final JsonToken NUMBER+
double
, long
, or int
.
++
+public static final JsonToken BOOLEAN+
true
or false
.
++
+public static final JsonToken NULL+
null
.
++
+public static final JsonToken END_DOCUMENT+
JsonReader.peek()
to signal that the JSON-encoded value has no more
+ tokens.
++
+Method Detail | +
---|
+public static JsonToken[] values()+
+for (JsonToken c : JsonToken.values()) + System.out.println(c); ++
+
+public static JsonToken valueOf(String name)+
+
name
- the name of the enum constant to be returned.
+IllegalArgumentException
- if this enum type has no constant
+with the specified name
+NullPointerException
- if the argument is null
+
+
|
++ + | +|||||||||
+ PREV CLASS + NEXT CLASS | ++ FRAMES + NO FRAMES + + + + + | +|||||||||
+ SUMMARY: NESTED | ENUM CONSTANTS | FIELD | METHOD | ++DETAIL: ENUM CONSTANTS | FIELD | METHOD | +
+
+
|
++ + | +|||||||||
+ PREV CLASS + NEXT CLASS | ++ FRAMES + NO FRAMES + + + + + | +|||||||||
+ SUMMARY: NESTED | FIELD | CONSTR | METHOD | ++DETAIL: FIELD | CONSTR | METHOD | +
+java.lang.Object + com.google.gson.stream.JsonWriter ++
public final class JsonWriter
+Writes a JSON (RFC 4627) + encoded value to a stream, one token at a time. The stream includes both + literal values (strings, numbers, booleans and nulls) as well as the begin + and end delimiters of objects and arrays. + +
JsonWriter
. Each JSON
+ document must contain one top-level array or object. Call methods on the
+ writer as you walk the structure's contents, nesting arrays and objects as
+ necessary:
+ beginArray()
.
+ Write each of the array's elements with the appropriate value(java.lang.String)
+ methods or by nesting other arrays and objects. Finally close the array
+ using endArray()
.
+ beginObject()
.
+ Write each of the object's properties by alternating calls to
+ name(java.lang.String)
with the property's value. Write property values with the
+ appropriate value(java.lang.String)
method or by nesting other objects or arrays.
+ Finally close the object using endObject()
.
+ [
+ {
+ "id": 912345678901,
+ "text": "How do I stream JSON in Java?",
+ "geo": null,
+ "user": {
+ "name": "json_newb",
+ "followers_count": 41
+ }
+ },
+ {
+ "id": 912345678902,
+ "text": "@json_newb just use JsonWriter!",
+ "geo": [50.454722, -104.606667],
+ "user": {
+ "name": "jesse",
+ "followers_count": 2
+ }
+ }
+ ]
+ This code encodes the above structure: public void writeJsonStream(OutputStream out, List<Message> messages) throws IOException {
+ JsonWriter writer = new JsonWriter(new OutputStreamWriter(out, "UTF-8"));
+ writer.setIndentSpaces(4);
+ writeMessagesArray(writer, messages);
+ writer.close();
+ }
+
+ public void writeMessagesArray(JsonWriter writer, List<Message> messages) throws IOException {
+ writer.beginArray();
+ for (Message message : messages) {
+ writeMessage(writer, message);
+ }
+ writer.endArray();
+ }
+
+ public void writeMessage(JsonWriter writer, Message message) throws IOException {
+ writer.beginObject();
+ writer.name("id").value(message.getId());
+ writer.name("text").value(message.getText());
+ if (message.getGeo() != null) {
+ writer.name("geo");
+ writeDoublesArray(writer, message.getGeo());
+ } else {
+ writer.name("geo").nullValue();
+ }
+ writer.name("user");
+ writeUser(writer, message.getUser());
+ writer.endObject();
+ }
+
+ public void writeUser(JsonWriter writer, User user) throws IOException {
+ writer.beginObject();
+ writer.name("name").value(user.getName());
+ writer.name("followers_count").value(user.getFollowersCount());
+ writer.endObject();
+ }
+
+ public void writeDoublesArray(JsonWriter writer, List<Double> doubles) throws IOException {
+ writer.beginArray();
+ for (Double value : doubles) {
+ writer.value(value);
+ }
+ writer.endArray();
+ }
+
+ Each JsonWriter
may be used to write a single JSON stream.
+ Instances of this class are not thread safe. Calls that would result in a
+ malformed JSON string will fail with an IllegalStateException
.
+
+ +
+
+Constructor Summary | +|
---|---|
JsonWriter(Writer out)
+
++ Creates a new instance that writes a JSON-encoded stream to out . |
+
+Method Summary | +|
---|---|
+ JsonWriter |
+beginArray()
+
++ Begins encoding a new array. |
+
+ JsonWriter |
+beginObject()
+
++ Begins encoding a new object. |
+
+ void |
+close()
+
++ Flushes and closes this writer and the underlying Writer . |
+
+ JsonWriter |
+endArray()
+
++ Ends encoding the current array. |
+
+ JsonWriter |
+endObject()
+
++ Ends encoding the current object. |
+
+ void |
+flush()
+
++ Ensures all buffered data is written to the underlying Writer
+ and flushes that writer. |
+
+ boolean |
+isHtmlSafe()
+
++ Returns true if this writer writes JSON that's safe for inclusion in HTML + and XML documents. |
+
+ boolean |
+isLenient()
+
++ Returns true if this writer has relaxed syntax rules. |
+
+ JsonWriter |
+name(String name)
+
++ Encodes the property name. |
+
+ JsonWriter |
+nullValue()
+
++ Encodes null . |
+
+ void |
+setHtmlSafe(boolean htmlSafe)
+
++ Configure this writer to emit JSON that's safe for direct inclusion in HTML + and XML documents. |
+
+ void |
+setIndent(String indent)
+
++ Sets the indentation string to be repeated for each level of indentation + in the encoded document. |
+
+ void |
+setLenient(boolean lenient)
+
++ Configure this writer to relax its syntax rules. |
+
+ JsonWriter |
+value(boolean value)
+
++ Encodes value . |
+
+ JsonWriter |
+value(double value)
+
++ Encodes value . |
+
+ JsonWriter |
+value(long value)
+
++ Encodes value . |
+
+ JsonWriter |
+value(Number value)
+
++ Encodes value . |
+
+ JsonWriter |
+value(String value)
+
++ Encodes value . |
+
Methods inherited from class java.lang.Object | +
---|
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
+
+Constructor Detail | +
---|
+public JsonWriter(Writer out)+
out
.
+ For best performance, ensure Writer
is buffered; wrapping in
+ BufferedWriter
if necessary.
++
+Method Detail | +
---|
+public void setIndent(String indent)+
indent.isEmpty()
the encoded document
+ will be compact. Otherwise the encoded document will be more
+ human-readable.
++
indent
- a string containing only whitespace.+public void setLenient(boolean lenient)+
NaNs
or infinities
.
+ +
+public boolean isLenient()+
+
+public void setHtmlSafe(boolean htmlSafe)+
<
, >
,
+ &
and =
before writing them to the stream. Without this
+ setting, your XML/HTML encoder should replace these characters with the
+ corresponding escape sequences.
++
+public boolean isHtmlSafe()+
+
+public JsonWriter beginArray() + throws IOException+
endArray()
.
++
IOException
+public JsonWriter endArray() + throws IOException+
+
IOException
+public JsonWriter beginObject() + throws IOException+
endObject()
.
++
IOException
+public JsonWriter endObject() + throws IOException+
+
IOException
+public JsonWriter name(String name) + throws IOException+
+
name
- the name of the forthcoming value. May not be null.
+IOException
+public JsonWriter value(String value) + throws IOException+
value
.
++
value
- the literal string value, or null to encode a null literal.
+IOException
+public JsonWriter nullValue() + throws IOException+
null
.
++
IOException
+public JsonWriter value(boolean value) + throws IOException+
value
.
++
IOException
+public JsonWriter value(double value) + throws IOException+
value
.
++
value
- a finite value. May not be NaNs
or
+ infinities
.
+IOException
+public JsonWriter value(long value) + throws IOException+
value
.
++
IOException
+public JsonWriter value(Number value) + throws IOException+
value
.
++
value
- a finite value. May not be NaNs
or
+ infinities
.
+IOException
+public void flush() + throws IOException+
Writer
+ and flushes that writer.
++
IOException
+public void close() + throws IOException+
Writer
.
++
close
in interface Closeable
IOException
- if the JSON document is incomplete.
+
+
|
++ + | +|||||||||
+ PREV CLASS + NEXT CLASS | ++ FRAMES + NO FRAMES + + + + + | +|||||||||
+ SUMMARY: NESTED | FIELD | CONSTR | METHOD | ++DETAIL: FIELD | CONSTR | METHOD | +
+
+
|
++ + | +|||||||||
+ PREV CLASS + NEXT CLASS | ++ FRAMES + NO FRAMES + + + + + | +|||||||||
+ SUMMARY: NESTED | FIELD | CONSTR | METHOD | ++DETAIL: FIELD | CONSTR | METHOD | +
+java.lang.Object + java.lang.Throwable + java.lang.Exception + java.io.IOException + com.google.gson.stream.MalformedJsonException ++
public final class MalformedJsonException
+Thrown when a reader encounters malformed JSON. Some syntax errors can be
+ ignored by calling JsonReader.setLenient(boolean)
.
+
+ +
+
+Constructor Summary | +|
---|---|
MalformedJsonException(String msg)
+
++ |
+|
MalformedJsonException(String msg,
+ Throwable throwable)
+
++ |
+|
MalformedJsonException(Throwable throwable)
+
++ |
+
+Method Summary | +
---|
Methods inherited from class java.lang.Throwable | +
---|
fillInStackTrace, getCause, getLocalizedMessage, getMessage, getStackTrace, initCause, printStackTrace, printStackTrace, printStackTrace, setStackTrace, toString |
+
Methods inherited from class java.lang.Object | +
---|
equals, getClass, hashCode, notify, notifyAll, wait, wait, wait |
+
+Constructor Detail | +
---|
+public MalformedJsonException(String msg)+
+public MalformedJsonException(String msg, + Throwable throwable)+
+public MalformedJsonException(Throwable throwable)+
+
+
|
++ + | +|||||||||
+ PREV CLASS + NEXT CLASS | ++ FRAMES + NO FRAMES + + + + + | +|||||||||
+ SUMMARY: NESTED | FIELD | CONSTR | METHOD | ++DETAIL: FIELD | CONSTR | METHOD | +
+
+
|
++ + | +|||||||||
+ PREV + NEXT | ++ FRAMES + NO FRAMES + + + + + | +
+Packages that use JsonReader | +|
---|---|
com.google.gson | +This package provides the Gson class to convert Json to Java and
+ vice-versa. |
+
+Uses of JsonReader in com.google.gson | +
---|
+ +
Methods in com.google.gson with parameters of type JsonReader | +||
---|---|---|
+
+ |
+Gson.fromJson(JsonReader reader,
+ Type typeOfT)
+
++ Reads the next JSON value from reader and convert it to an object
+ of type typeOfT . |
+|
+ JsonElement |
+JsonParser.parse(JsonReader json)
+
++ Returns the next value from the JSON stream as a parse tree. |
+
+
+
+
|
++ + | +|||||||||
+ PREV + NEXT | ++ FRAMES + NO FRAMES + + + + + | +
+
+
|
++ + | +|||||||||
+ PREV + NEXT | ++ FRAMES + NO FRAMES + + + + + | +
+Packages that use JsonToken | +|
---|---|
com.google.gson.stream | ++ |
+Uses of JsonToken in com.google.gson.stream | +
---|
+ +
Methods in com.google.gson.stream that return JsonToken | +|
---|---|
+ JsonToken |
+JsonReader.peek()
+
++ Returns the type of the next token without consuming it. |
+
+static JsonToken |
+JsonToken.valueOf(String name)
+
++ Returns the enum constant of this type with the specified name. |
+
+static JsonToken[] |
+JsonToken.values()
+
++ Returns an array containing the constants of this enum type, in +the order they are declared. |
+
+
+
+
|
++ + | +|||||||||
+ PREV + NEXT | ++ FRAMES + NO FRAMES + + + + + | +
+
+
|
++ + | +|||||||||
+ PREV + NEXT | ++ FRAMES + NO FRAMES + + + + + | +
+Packages that use JsonWriter | +|
---|---|
com.google.gson | +This package provides the Gson class to convert Json to Java and
+ vice-versa. |
+
com.google.gson.stream | ++ |
+Uses of JsonWriter in com.google.gson | +
---|
+ +
Methods in com.google.gson with parameters of type JsonWriter | +|
---|---|
+ void |
+Gson.toJson(JsonElement jsonElement,
+ JsonWriter writer)
+
++ Writes the JSON for jsonElement to writer . |
+
+ void |
+Gson.toJson(Object src,
+ Type typeOfSrc,
+ JsonWriter writer)
+
++ Writes the JSON representation of src of type typeOfSrc to
+ writer . |
+
+Uses of JsonWriter in com.google.gson.stream | +
---|
+ +
Methods in com.google.gson.stream that return JsonWriter | +|
---|---|
+ JsonWriter |
+JsonWriter.beginArray()
+
++ Begins encoding a new array. |
+
+ JsonWriter |
+JsonWriter.beginObject()
+
++ Begins encoding a new object. |
+
+ JsonWriter |
+JsonWriter.endArray()
+
++ Ends encoding the current array. |
+
+ JsonWriter |
+JsonWriter.endObject()
+
++ Ends encoding the current object. |
+
+ JsonWriter |
+JsonWriter.name(String name)
+
++ Encodes the property name. |
+
+ JsonWriter |
+JsonWriter.nullValue()
+
++ Encodes null . |
+
+ JsonWriter |
+JsonWriter.value(boolean value)
+
++ Encodes value . |
+
+ JsonWriter |
+JsonWriter.value(double value)
+
++ Encodes value . |
+
+ JsonWriter |
+JsonWriter.value(long value)
+
++ Encodes value . |
+
+ JsonWriter |
+JsonWriter.value(Number value)
+
++ Encodes value . |
+
+ JsonWriter |
+JsonWriter.value(String value)
+
++ Encodes value . |
+
+
+
+
|
++ + | +|||||||||
+ PREV + NEXT | ++ FRAMES + NO FRAMES + + + + + | +
+
+
|
++ + | +|||||||||
+ PREV + NEXT | ++ FRAMES + NO FRAMES + + + + + | +
+
+
+
|
++ + | +|||||||||
+ PREV + NEXT | ++ FRAMES + NO FRAMES + + + + + | +
+Classes
+
+ +JsonReader + +JsonWriter |
+
+Enums
+
+ +JsonToken |
+
+Exceptions
+
+ +MalformedJsonException |
+
+
+
|
++ + | +|||||||||
+ PREV PACKAGE + NEXT PACKAGE | ++ FRAMES + NO FRAMES + + + + + | +
+Class Summary | +|
---|---|
JsonReader | +Reads a JSON (RFC 4627) + encoded value as a stream of tokens. | +
JsonWriter | +Writes a JSON (RFC 4627) + encoded value to a stream, one token at a time. | +
+ +
+Enum Summary | +|
---|---|
JsonToken | +A structure, name or value type in a JSON-encoded string. | +
+ +
+Exception Summary | +|
---|---|
MalformedJsonException | +Thrown when a reader encounters malformed JSON. | +
+
+
+
|
++ + | +|||||||||
+ PREV PACKAGE + NEXT PACKAGE | ++ FRAMES + NO FRAMES + + + + + | +
+
+
|
++ + | +|||||||||
+ PREV + NEXT | ++ FRAMES + NO FRAMES + + + + + | +
+
+
|
++ + | +|||||||||
+ PREV + NEXT | ++ FRAMES + NO FRAMES + + + + + | +
+
+
|
++ + | +|||||||||
+ PREV + NEXT | ++ FRAMES + NO FRAMES + + + + + | +
+Packages that use com.google.gson.stream | +|
---|---|
com.google.gson | +This package provides the Gson class to convert Json to Java and
+ vice-versa. |
+
com.google.gson.stream | ++ |
+Classes in com.google.gson.stream used by com.google.gson | +|
---|---|
JsonReader
+
+ + Reads a JSON (RFC 4627) + encoded value as a stream of tokens. |
+|
JsonWriter
+
+ + Writes a JSON (RFC 4627) + encoded value to a stream, one token at a time. |
+
+Classes in com.google.gson.stream used by com.google.gson.stream | +|
---|---|
JsonToken
+
+ + A structure, name or value type in a JSON-encoded string. |
+|
JsonWriter
+
+ + Writes a JSON (RFC 4627) + encoded value to a stream, one token at a time. |
+
+
+
+
|
++ + | +|||||||||
+ PREV + NEXT | ++ FRAMES + NO FRAMES + + + + + | +
+
+
|
++ + | +|||||||||
+ PREV + NEXT | ++ FRAMES + NO FRAMES + + + + + | +
+
+
|
++ + | +|||||||||
+ PREV + NEXT | ++ FRAMES + NO FRAMES + + + + + | +
+
+
|
++ + | +|||||||||
+ PREV + NEXT | ++ FRAMES + NO FRAMES + + + + + | +
+
+
|
++ + | +|||||||||
+ PREV + NEXT | ++ FRAMES + NO FRAMES + + + + + | +
+
+
|
++ + | +|||||||||
+ PREV + NEXT | ++ FRAMES + NO FRAMES + + + + + | +
+ +++The Overview page is the front page of this API document and provides a list of all packages with a summary for each. This page can also contain an overall description of the set of packages.
+ +++Each package has a page that contains a list of its classes and interfaces, with a summary for each. This page can contain four categories:
+
+- Interfaces (italic)
- Classes
- Enums
- Exceptions
- Errors
- Annotation Types
+ ++ ++Each class, interface, nested class and nested interface has its own separate page. Each of these pages has three sections consisting of a class/interface description, summary tables, and detailed member descriptions:
+
+Each summary entry contains the first sentence from the detailed description for that item. The summary entries are alphabetical, while the detailed descriptions are in the order they appear in the source code. This preserves the logical groupings established by the programmer.- Class inheritance diagram
- Direct Subclasses
- All Known Subinterfaces
- All Known Implementing Classes
- Class/interface declaration
- Class/interface description +
+
- Nested Class Summary
- Field Summary
- Constructor Summary
- Method Summary +
+
- Field Detail
- Constructor Detail
- Method Detail
+ ++ ++Each annotation type has its own separate page with the following sections:
+
+- Annotation Type declaration
- Annotation Type description
- Required Element Summary
- Optional Element Summary
- Element Detail
+ +++Each enum has its own separate page with the following sections:
+
+- Enum declaration
- Enum description
- Enum Constant Summary
- Enum Constant Detail
+Each documented package, class and interface has its own Use page. This page describes what packages, classes, methods, constructors and fields use any part of the given class or package. Given a class or interface A, its Use page includes subclasses of A, fields declared as A, methods that return A, and methods and constructors with parameters of type A. You can access this page by first going to the package, class or interface, then clicking on the "Use" link in the navigation bar.+
+There is a Class Hierarchy page for all packages, plus a hierarchy for each package. Each hierarchy page contains a list of classes and a list of interfaces. The classes are organized by inheritance structure starting with+java.lang.Object
. The interfaces do not inherit fromjava.lang.Object
.+
+- When viewing the Overview page, clicking on "Tree" displays the hierarchy for all packages.
- When viewing a particular package, class or interface page, clicking "Tree" displays the hierarchy for only that package.
+The Deprecated API page lists all of the API that have been deprecated. A deprecated API is not recommended for use, generally due to improvements, and a replacement API is usually given. Deprecated APIs may be removed in future implementations.+
+The Index contains an alphabetic list of all classes, interfaces, constructors, methods, and fields.+
+
+
+
+
+This help file applies to API documentation generated using the standard doclet.
+
+
+
+
+
|
++ + | +|||||||||
+ PREV + NEXT | ++ FRAMES + NO FRAMES + + + + + | +
+
+
|
++ + | +|||||||||
+ PREV + NEXT | ++ FRAMES + NO FRAMES + + + + + | +
Reader
.
+Writer
.
+Gson
class to convert Json to Java and
+ vice-versa.Gson
.Gson
instance based on the current configuration.
+Expose
annotation.
+Writer
+ and flushes that writer.
+reader
and convert it to an object
+ of type typeOfT
.
+Type
instance.
+Class
instance.
+T
annotation object from this field if it exist; otherwise returns
+ null
.
+BigDecimal
if it contains a single element.
+BigDecimal
.
+BigDecimal
.
+BigInteger
if it contains a single element.
+BigInteger
.
+BigInteger
.
+JsonArray
.
+JsonNull
.
+JsonObject
.
+JsonPrimitive
.
+Number
if it contains a single element.
+Number
.
+String
if it contains a single element.
+Class<?>
object that was declared for this field.
++ public class Foo { + private String bar; + private List<String> red; + } + + Type listParmeterizedType = new TypeToken>() {}.getType(); +
- getDeclaringClass() - +Method in class com.google.gson.FieldAttributes +
- +
- getName() - +Method in class com.google.gson.FieldAttributes +
- +
- getRawType() - +Method in class com.google.gson.reflect.TypeToken +
- Gets the raw type. +
- getType() - +Method in class com.google.gson.reflect.TypeToken +
- Gets underlying
Type
instance. +- Gson - Class in com.google.gson
- This is the main class for using Gson.
- Gson() - +Constructor for class com.google.gson.Gson +
- Constructs a Gson object with default configuration. +
- GsonBuilder - Class in com.google.gson
- Use this builder to construct a
Gson
instance when you need to set configuration + options other than the default.- GsonBuilder() - +Constructor for class com.google.gson.GsonBuilder +
- Creates a GsonBuilder instance that can be used to build Gson with various configuration + settings. +
true
if the field is defined with the modifier
.
+JsonElement
is available on the input for consumption
+JsonDeserializer.deserialize(JsonElement, Type, JsonDeserializationContext)
+ method.null
value.JsonElement
sNumber
.
+in
.
+JsonSerializer.serialize(Object, Type, JsonSerializationContext)
method.JsonElement
s from the specified reader
+ asynchronously.out
.
+long
or Long
type when its serialized.JsonElement
on the reader.
+boolean
value of the next token,
+ consuming it.
+double
value of the next token,
+ consuming it.
+int
value of the next token,
+ consuming it.
+long
value of the next token,
+ consuming it.
+property name
, and
+ consumes it.
+string
value of the next token,
+ consuming it.
+null
.
+property
from this JsonObject
.
+Iterator
method is not relevant for stream parsing and hence is not
+ implemented.
+value
using this serialization policy.
+Date
objects according to the pattern provided.
+Date
objects according to the style value provided.
+Date
objects according to the style value provided.
+Long
and long
+ objects.
+src
of type typeOfSrc
to
+ writer
.
+JsonElement
s into its equivalent JSON representation.
+JsonElement
s.
+jsonElement
to writer
.
+JsonElement
s.
+JsonElement
s.
+T
.value
.
+value
.
+value
.
+value
.
+value
.
+
+
+
|
++ + | +|||||||||
+ PREV + NEXT | ++ FRAMES + NO FRAMES + + + + + | +
+ | +
---|
All Classes
+
+
+Packages
+ |
+
+ + + diff --git a/gson/docs/javadocs/overview-summary.html b/gson/docs/javadocs/overview-summary.html new file mode 100644 index 00000000..c3cbd72f --- /dev/null +++ b/gson/docs/javadocs/overview-summary.html @@ -0,0 +1,170 @@ + + + +
+ + +
+
+
|
++ + | +|||||||||
+ PREV + NEXT | ++ FRAMES + NO FRAMES + + + + + | +
+Packages | +|
---|---|
com.google.gson | +This package provides the Gson class to convert Json to Java and
+ vice-versa. |
+
com.google.gson.annotations | +This package provides annotations that can be used with Gson . |
+
com.google.gson.reflect | +This package provides utility classes for finding type information for generic types. | +
com.google.gson.stream | ++ |
+
+
+
|
++ + | +|||||||||
+ PREV + NEXT | ++ FRAMES + NO FRAMES + + + + + | +
+
+
|
++ + | +|||||||||
+ PREV + NEXT | ++ FRAMES + NO FRAMES + + + + + | +
+
+
|
++ + | +|||||||||
+ PREV + NEXT | ++ FRAMES + NO FRAMES + + + + + | +
+
+
|
++ + | +|||||||||
+ PREV + NEXT | ++ FRAMES + NO FRAMES + + + + + | +
+Package com.google.gson | +
---|
+Class com.google.gson.JsonIOException extends JsonParseException implements Serializable | +
---|
+serialVersionUID: 1L + +
+ +
+Class com.google.gson.JsonParseException extends RuntimeException implements Serializable | +
---|
+serialVersionUID: -4086729973971783390L + +
+ +
+Class com.google.gson.JsonSyntaxException extends JsonParseException implements Serializable | +
---|
+serialVersionUID: 1L + +
+
+Package com.google.gson.stream | +
---|
+Class com.google.gson.stream.MalformedJsonException extends IOException implements Serializable | +
---|
+serialVersionUID: 1L + +
+ +
+
+
+
|
++ + | +|||||||||
+ PREV + NEXT | ++ FRAMES + NO FRAMES + + + + + | +