Package com.alibaba.fastjson2
Enum PropertyNamingStrategy
- All Implemented Interfaces:
Serializable,Comparable<PropertyNamingStrategy>,java.lang.constant.Constable
An enumeration that defines a few standard naming conventions for JSON field names.
This enum provides various naming strategies that can be used to transform Java field names to different JSON field naming conventions. For example, camelCase can be transformed to snake_case, kebab-case, or other formats.
Example usage:
// Using snake_case naming strategy
PropertyNamingStrategy.SnakeCase.fieldName("userName"); // returns "user_name"
// Using PascalCase naming strategy
PropertyNamingStrategy.PascalCase.fieldName("userName"); // returns "UserName"
- Since:
- 1.2.15
- Author:
- wenshao[szujobs@hotmail.com]
-
Nested Class Summary
Nested classes/interfaces inherited from class java.lang.Enum
Enum.EnumDesc<E extends Enum<E>> -
Enum Constant Summary
Enum ConstantsEnum ConstantDescriptionfor fastjson 1.x compatibleUsing this naming policy with FASTJSON 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 FASTJSON 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 FASTJSON 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 FASTJSON 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 FASTJSON will ensure that the first "letter" of the Java field name is capitalized when serialized to its JSON form.Using this naming policy with FASTJSON 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 dash (-).Using this naming policy with FASTJSON 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 dash (-).Using this naming policy with FASTJSON 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 FASTJSON 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 an underscore (_).Using this naming policy with FASTJSON will modify the Java Field name from its camel cased form to an upper case field name where each word is separated by a dash (-).Using this naming policy with FASTJSON will modify the Java Field name from its camel cased form to an upper case field name where each word is separated by a dot (.).Using this naming policy with FASTJSON 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 TypeMethodDescriptionTransforms the given field name according to this naming strategy.static PropertyNamingStrategyReturns the PropertyNamingStrategy enum constant with the specified name.static StringsnakeToCamel(String name) Converts a snake_case string to camelCase.static PropertyNamingStrategyReturns the enum constant of this type with the specified name.static PropertyNamingStrategy[]values()Returns an array containing the constants of this enum type, in the order they are declared.
-
Enum Constant Details
-
CamelCase
-
CamelCase1x
for fastjson 1.x compatible -
PascalCase
Using this naming policy with FASTJSON 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 -
SnakeCase
-
UpperCase
-
UpperCamelCaseWithSpaces
Using this naming policy with FASTJSON 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:
- 2.0.7
-
UpperCamelCaseWithUnderScores
Using this naming policy with FASTJSON 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 an underscore (_). Here are a few examples of the form "Java Field Name" ---> "JSON Field Name": someFieldName ---> Some_Field_Name _someFieldName ---> _Some_Field_Name- Since:
- 2.0.7
-
UpperCamelCaseWithDashes
Using this naming policy with FASTJSON 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 dash (-). Here are a few examples of the form "Java Field Name" ---> "JSON Field Name": someFieldName ---> Some-Field-Name _someFieldName ---> _Some-Field-Name- Since:
- 2.0.7
-
UpperCamelCaseWithDots
Using this naming policy with FASTJSON 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 dash (-). Here are a few examples of the form "Java Field Name" ---> "JSON Field Name": someFieldName ---> Some-Field-Name _someFieldName ---> _Some-Field-Name- Since:
- 2.0.7
-
KebabCase
Using this naming policy with FASTJSON 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. -
UpperCaseWithUnderScores
Using this naming policy with FASTJSON 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.0.7
-
UpperCaseWithDashes
Using this naming policy with FASTJSON will modify the Java Field name from its camel cased form to an upper 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- Since:
- 2.0.8
-
UpperCaseWithDots
Using this naming policy with FASTJSON will modify the Java Field name from its camel cased form to an upper 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- Since:
- 2.0.8
-
LowerCase
-
LowerCaseWithUnderScores
Using this naming policy with FASTJSON 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- Since:
- 2.0.7
-
LowerCaseWithDashes
Using this naming policy with FASTJSON 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:
- 2.0.7
-
LowerCaseWithDots
Using this naming policy with FASTJSON 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.0.7
-
NeverUseThisValueExceptDefaultValue
-
-
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
-
fieldName
Transforms the given field name according to this naming strategy.- Parameters:
name- the original field name in Java (typically camelCase)- Returns:
- the transformed field name according to the naming strategy
-
snakeToCamel
Converts a snake_case string to camelCase.For example:
- "user_name" becomes "userName"
- "first_name" becomes "firstName"
- "url" remains "url" (no underscores)
- Parameters:
name- the snake_case string to convert- Returns:
- the camelCase string, or the original string if it doesn't contain underscores
-
of
Returns the PropertyNamingStrategy enum constant with the specified name.The string matching is case-insensitive for common aliases:
Other strategy names are matched case-sensitively against the enum constant names.- Parameters:
strategy- the name of the strategy to find, or null/empty to return null- Returns:
- the PropertyNamingStrategy with the specified name, or null if not found
-