Top Description Fields Constructors Methods
com.google.gson

public sealed Enum FieldNamingPolicy

extends Enum<FieldNamingPolicy>
implements FieldNamingStrategy
Class Inheritance
All Implemented Interfaces
com.google.gson.FieldNamingStrategy
Imports
java.lang.reflect.Field, java.util.Locale

An enumeration that defines a few standard naming conventions for JSON field names. This enumeration should be used in conjunction with com.google.gson.GsonBuilder to configure a com.google.gson.Gson instance to properly translate Java field names into the desired JSON field names.
Authors
Inderjeet Singh, Joel Leitch

Field Summary

Modifier and TypeField and Description
public static final FieldNamingPolicy
IDENTITY

Using this naming policy with Gson will ensure that the field name is unchanged.

public static final FieldNamingPolicy
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 (-).

public static final FieldNamingPolicy
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 (.).

public static final FieldNamingPolicy
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 (_).

public static final FieldNamingPolicy
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.

public static final FieldNamingPolicy
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.

public static final FieldNamingPolicy
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 (_).

Constructor Summary

AccessConstructor and Description
private

Method Summary

Modifier and TypeMethod and Description
pack-priv static String
separateCamelCase(String name, char separator)

Converts the field name that uses camel-case define word separation into separate words that are separated by the provided separator.

pack-priv static String
upperCaseFirstLetter(String s)

Ensures the JSON field names begins with an upper case letter.

public static FieldNamingPolicy
public static FieldNamingPolicy[]
Inherited from java.lang.Enum:
clonecompareTodescribeConstableequalsfinalizegetDeclaringClasshashCodenameordinaltoStringvalueOf

Field Detail

IDENTITYback to summary
public static final FieldNamingPolicy IDENTITY

Using this naming policy with Gson will ensure that the field name is unchanged.

LOWER_CASE_WITH_DASHESback to summary
public static final FieldNamingPolicy 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
Using dashes in JavaScript is not recommended since dash is also used for a minus sign in expressions. This requires that a field named with dashes is always accessed as a quoted property like myobject['my-field']. Accessing it as an object field myobject.my-field will result in an unintended JavaScript expression.
Since
1.4
LOWER_CASE_WITH_DOTSback to summary
public static final FieldNamingPolicy 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
Using dots in JavaScript is not recommended since dot is also used for a member sign in expressions. This requires that a field named with dots is always accessed as a quoted property like myobject['my.field']. Accessing it as an object field myobject.my.field will result in an unintended JavaScript expression.
Since
2.8.4
LOWER_CASE_WITH_UNDERSCORESback to summary
public static final FieldNamingPolicy 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
UPPER_CAMEL_CASEback to summary
public static final FieldNamingPolicy 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_SPACESback to summary
public static final FieldNamingPolicy 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_UNDERSCORESback to summary
public static final FieldNamingPolicy 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

Constructor Detail

FieldNamingPolicyback to summary
private FieldNamingPolicy()

Method Detail

separateCamelCaseback to summary
pack-priv static String separateCamelCase(String name, char separator)

Converts the field name that uses camel-case define word separation into separate words that are separated by the provided separator.

upperCaseFirstLetterback to summary
pack-priv static String upperCaseFirstLetter(String s)

Ensures the JSON field names begins with an upper case letter.

valueOfback to summary
public static FieldNamingPolicy valueOf(String name)
valuesback to summary
public static FieldNamingPolicy[] values()