| AndBase开发框架 1.6

- 首页
- 相关页面
- 命名空间
- 类
- 文件

- 类列表
- 类索引
- 类继承关系
- 类成员

全部 类 命名空间 文件 函数 变量 枚举值 页
Public 成员函数 | 包函数 | 包属性 | 静态包属性 | Private 成员函数 | Private 属性 | 静态 Private 属性 | 所有成员列表
com.google.gson.Gson类 参考

## Public 成员函数
| Gson ()

## 包函数
| Gson (final Excluder excluder, final FieldNamingStrategy fieldNamingPolicy, final Map< Type, InstanceCreator<?>> instanceCreators, boolean serializeNulls, boolean complexMapKeySerialization, boolean generateNonExecutableGson, boolean htmlSafe, boolean prettyPrinting, boolean serializeSpecialFloatingPointValues, LongSerializationPolicy longSerializationPolicy, List< TypeAdapterFactory > typeAdapterFactories)

## 包属性
final JsonDeserializationContext | deserializationContext
final JsonSerializationContext | serializationContext

## 静态包属性
static final boolean | DEFAULT_JSON_NON_EXECUTABLE = false

## Private 成员函数
TypeAdapter< Number > | doubleAdapter (boolean serializeSpecialFloatingPointValues)
TypeAdapter< Number > | floatAdapter (boolean serializeSpecialFloatingPointValues)
void | checkValidFloatingPoint (double value)
TypeAdapter< Number > | longAdapter (LongSerializationPolicy longSerializationPolicy)

## Private 属性
final ThreadLocal< Map < TypeToken <?>, FutureTypeAdapter<?> > > | calls
final Map< TypeToken <?>, TypeAdapter<?> > | typeTokenCache = Collections.synchronizedMap(new HashMap<TypeToken<?>, TypeAdapter<?>>())
final List< TypeAdapterFactory > | factories
final ConstructorConstructor | constructorConstructor
final boolean | serializeNulls
final boolean | htmlSafe
final boolean | generateNonExecutableJson
final boolean | prettyPrinting

## 静态 Private 属性
static final String | JSON_NON_EXECUTABLE_PREFIX = ")]}'\n"

## 详细描述

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 JsonSerializers, JsonDeserializers, and InstanceCreators.

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.

参见
  com.google.gson.reflect.TypeToken

作者
  Inderjeet Singh
  Joel Leitch

## 构造及析构函数说明

com.google.gson.Gson.Gson | ( |  | ) |
| inline

Constructs a Gson object with default configuration. The default configuration has the following settings:

- The JSON generated by `toJson` methods is in compact representation. This means that all the unneeded white-space is removed. You can change this behavior with GsonBuilder#setPrettyPrinting().
- The generated JSON omits all the fields that are null. Note that nulls in arrays are kept as is since an array is an ordered list. Moreover, if a field is not null, but its generated JSON is empty, the field is kept. You can configure Gson to serialize null values by setting GsonBuilder#serializeNulls().
- Gson provides default serialization and deserialization for Enums, Map, java.net.URL, java.net.URI, java.util.Locale, java.util.Date, java.math.BigDecimal, and java.math.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).
- The default Date format is same as java.text.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).
- By default, Gson ignores the com.google.gson.annotations.Expose annotation. You can enable Gson to serialize/deserialize only those fields marked with this annotation through GsonBuilder#excludeFieldsWithoutExposeAnnotation().
- By default, Gson ignores the com.google.gson.annotations.Since annotation. You can enable Gson to use this annotation through GsonBuilder#setVersion(double).
- The default field naming policy for the output Json is same as in Java. So, a Java class field `versionNumber` will be output as `"versionNumber;` in Json. The same rules are applied for mapping incoming Json to the Java classes. You can change this policy through GsonBuilder#setFieldNamingPolicy(FieldNamingPolicy).
- By default, Gson excludes `transient` or `static` fields from consideration for serialization and deserialization. You can change this behavior through GsonBuilder#excludeFieldsWithModifiers(int...).

com.google.gson.Gson.Gson | ( | final Excluder | excluder,
|  | final FieldNamingStrategy | fieldNamingPolicy,
|  | final Map< Type, InstanceCreator<?>> | instanceCreators,
|  | boolean | serializeNulls,
|  | boolean | complexMapKeySerialization,
|  | boolean | generateNonExecutableGson,
|  | boolean | htmlSafe,
|  | boolean | prettyPrinting,
|  | boolean | serializeSpecialFloatingPointValues,
|  | LongSerializationPolicy | longSerializationPolicy,
|  | List< TypeAdapterFactory > | typeAdapterFactories
| ) |  |
| inline package

## 成员函数说明

void com.google.gson.Gson.checkValidFloatingPoint | ( | double | value | ) |
| inline private

TypeAdapter<Number> com.google.gson.Gson.doubleAdapter | ( | boolean | serializeSpecialFloatingPointValues | ) |
| inline private

TypeAdapter<Number> com.google.gson.Gson.floatAdapter | ( | boolean | serializeSpecialFloatingPointValues | ) |
| inline private

TypeAdapter<Number> com.google.gson.Gson.longAdapter | ( | LongSerializationPolicy | longSerializationPolicy | ) |
| inline private

## 类成员变量说明

final ThreadLocal<Map<TypeToken<?>, FutureTypeAdapter<?> > > com.google.gson.Gson.calls
| private

初始值:
= new ThreadLocal<Map<TypeToken<?>, FutureTypeAdapter<?>>>() {
@Override protected Map<TypeToken<?>, FutureTypeAdapter<?>> initialValue() {
return new HashMap<TypeToken<?>, FutureTypeAdapter<?>>();
}
}

This thread local guards against reentrant calls to getAdapter(). In certain object graphs, creating an adapter for a type may recursively require an adapter for the same type! Without intervention, the recursive lookup would stack overflow. We cheat by returning a proxy type adapter. The proxy is wired up once the initial adapter has been created.

final ConstructorConstructor com.google.gson.Gson.constructorConstructor
| private

final boolean com.google.gson.Gson.DEFAULT_JSON_NON_EXECUTABLE = false
| static package

final JsonDeserializationContext com.google.gson.Gson.deserializationContext
| package

初始值:
= new JsonDeserializationContext() {
@SuppressWarnings("unchecked")
public <T> T deserialize(JsonElement json, Type typeOfT) throws JsonParseException {
return (T) fromJson(json, typeOfT);
}
}

final List<TypeAdapterFactory> com.google.gson.Gson.factories
| private

final boolean com.google.gson.Gson.generateNonExecutableJson
| private

final boolean com.google.gson.Gson.htmlSafe
| private

final String com.google.gson.Gson.JSON_NON_EXECUTABLE_PREFIX = ")]}'\n"
| static private

final boolean com.google.gson.Gson.prettyPrinting
| private

final JsonSerializationContext com.google.gson.Gson.serializationContext
| package

初始值:
= new JsonSerializationContext() {
public JsonElement serialize(Object src) {
return toJsonTree(src);
}
public JsonElement serialize(Object src, Type typeOfSrc) {
return toJsonTree(src, typeOfSrc);
}
}

final boolean com.google.gson.Gson.serializeNulls
| private

final Map<TypeToken<?>, TypeAdapter<?> > com.google.gson.Gson.typeTokenCache = Collections.synchronizedMap(new HashMap<TypeToken<?>, TypeAdapter<?>>())
| private

该类的文档由以下文件生成:

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