Enum FieldNamingPolicy

  • All Implemented Interfaces:
    FieldNamingStrategy, java.io.Serializable, java.lang.Comparable<FieldNamingPolicy>

    public enum FieldNamingPolicy
    extends java.lang.Enum<FieldNamingPolicy>
    implements FieldNamingStrategy
    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

      Enum Constants 
      Enum Constant Description
      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_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 (.).
      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

      All Methods Static Methods Concrete Methods 
      Modifier and Type Method Description
      static FieldNamingPolicy valueOf​(java.lang.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

      • IDENTITY

        public static final FieldNamingPolicy IDENTITY
        Using this naming policy with Gson will ensure that the field name is unchanged.
      • UPPER_CAMEL_CASE

        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's a few examples of the form "Java Field Name" ---> "JSON Field Name":

        • someFieldName ---> SomeFieldName
        • _someFieldName ---> _SomeFieldName
      • UPPER_CAMEL_CASE_WITH_SPACES

        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's a few examples of the form "Java Field Name" ---> "JSON Field Name":

        • someFieldName ---> Some Field Name
        • _someFieldName ---> _Some Field Name
        Since:
        1.4
      • LOWER_CASE_WITH_UNDERSCORES

        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's 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

        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's 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_DOTS

        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's 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
    • Method Detail

      • values

        public static FieldNamingPolicy[] values()
        Returns an array containing the constants of this enum type, in the order they are declared. This method may be used to iterate over the constants as follows:
        for (FieldNamingPolicy c : FieldNamingPolicy.values())
            System.out.println(c);
        
        Returns:
        an array containing the constants of this enum type, in the order they are declared
      • valueOf

        public static FieldNamingPolicy valueOf​(java.lang.String name)
        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:
        java.lang.IllegalArgumentException - if this enum type has no constant with the specified name
        java.lang.NullPointerException - if the argument is null