- All Implemented Interfaces:
FieldNamingStrategy
,Serializable
,Comparable<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.- Author:
- Inderjeet Singh, Joel Leitch
-
Enum Constant Summary
Enum ConstantDescriptionUsing this naming policy with Gson will ensure that the field name is unchanged.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 (-).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 dot (.).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 (_).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.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.Using this naming policy with Gson will modify the Java Field name from its camel cased form to an upper case field name where each word is separated by an underscore (_). -
Method Summary
Modifier and TypeMethodDescriptionstatic FieldNamingPolicy
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
clone, compareTo, equals, finalize, getDeclaringClass, hashCode, name, ordinal, toString, valueOf
Methods inherited from interface com.google.gson.FieldNamingStrategy
translateName
-
Enum Constant Details
-
IDENTITY
Using this naming policy with Gson will ensure that the field name is unchanged. -
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.Here are a few examples of the form "Java Field Name" ---> "JSON Field Name":
- someFieldName ---> SomeFieldName
- _someFieldName ---> _SomeFieldName
-
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.Here are a few examples of the form "Java Field Name" ---> "JSON Field Name":
- someFieldName ---> Some Field Name
- _someFieldName ---> _Some Field Name
- Since:
- 1.4
-
UPPER_CASE_WITH_UNDERSCORES
Using this naming policy with Gson will modify the Java Field name from its camel cased form to an upper case field name where each word is separated by an underscore (_).Here are a few examples of the form "Java Field Name" ---> "JSON Field Name":
- someFieldName ---> SOME_FIELD_NAME
- _someFieldName ---> _SOME_FIELD_NAME
- aStringField ---> A_STRING_FIELD
- aURL ---> A_U_R_L
- Since:
- 2.9.0
-
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 (_).Here are a few examples of the form "Java Field Name" ---> "JSON Field Name":
- someFieldName ---> some_field_name
- _someFieldName ---> _some_field_name
- aStringField ---> a_string_field
- aURL ---> a_u_r_l
-
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 (-).Here are a few examples of the form "Java Field Name" ---> "JSON Field Name":
- someFieldName ---> some-field-name
- _someFieldName ---> _some-field-name
- aStringField ---> a-string-field
- aURL ---> a-u-r-l
myobject['my-field']
. Accessing it as an object fieldmyobject.my-field
will result in an unintended JavaScript expression.- Since:
- 1.4
-
LOWER_CASE_WITH_DOTS
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 dot (.).Here are a few examples of the form "Java Field Name" ---> "JSON Field Name":
- someFieldName ---> some.field.name
- _someFieldName ---> _some.field.name
- aStringField ---> a.string.field
- aURL ---> a.u.r.l
myobject['my.field']
. Accessing it as an object fieldmyobject.my.field
will result in an unintended JavaScript expression.- Since:
- 2.8.4
-
-
Method Details
-
values
Returns an array containing the constants of this enum type, in the order they are declared.- Returns:
- an array containing the constants of this enum type, in the order they are declared
-
valueOf
Returns the enum constant of this type with the specified name. The string must match exactly an identifier used to declare an enum constant in this type. (Extraneous whitespace characters are not permitted.)- Parameters:
name
- the name of the enum constant to be returned.- Returns:
- the enum constant with the specified name
- Throws:
IllegalArgumentException
- if this enum type has no constant with the specified nameNullPointerException
- if the argument is null
-