public enum FieldNamingPolicy extends Enum<FieldNamingPolicy> implements FieldNamingStrategy
GsonBuilder
to configure a Gson
instance to properly translate Java field
names into the desired JSON field names.枚举常量和说明 |
---|
IDENTITY
Using this naming policy with Gson will ensure that the field name is
unchanged.
|
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.
|
限定符和类型 | 方法和说明 |
---|---|
static FieldNamingPolicy |
valueOf(String name)
返回带有指定名称的该类型的枚举常量。
|
static FieldNamingPolicy[] |
values()
按照声明该枚举类型的常量的顺序, 返回
包含这些常量的数组。
|
clone, compareTo, equals, finalize, getDeclaringClass, hashCode, name, ordinal, toString, valueOf
translateName
public static final FieldNamingPolicy IDENTITY
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.public static FieldNamingPolicy[] values()
for (FieldNamingPolicy c : FieldNamingPolicy.values()) System.out.println(c);
public static FieldNamingPolicy valueOf(String name)
name
- 要返回的枚举常量的名称。IllegalArgumentException
- 如果该枚举类型没有带有指定名称的常量NullPointerException
- 如果参数为空值