Package com.fasterxml.jackson.databind
Class PropertyNamingStrategies.SnakeCaseStrategy
- java.lang.Object
-
- com.fasterxml.jackson.databind.PropertyNamingStrategy
-
- com.fasterxml.jackson.databind.PropertyNamingStrategies.NamingBase
-
- com.fasterxml.jackson.databind.PropertyNamingStrategies.SnakeCaseStrategy
-
- All Implemented Interfaces:
java.io.Serializable
- Direct Known Subclasses:
PropertyNamingStrategies.UpperSnakeCaseStrategy
- Enclosing class:
- PropertyNamingStrategies
public static class PropertyNamingStrategies.SnakeCaseStrategy extends PropertyNamingStrategies.NamingBase
APropertyNamingStrategy
that translates typical camel case Java property names to lower case JSON element names, separated by underscores. This implementation is somewhat lenient, in that it provides some additional translations beyond strictly translating from camel case only. In particular, the following translations are applied by this PropertyNamingStrategy.- Every upper case letter in the Java property name is translated
into two characters, an underscore and the lower case equivalent of the
target character, with three exceptions.
- For contiguous sequences of upper case letters, characters after
the first character are replaced only by their lower case equivalent,
and are not preceded by an underscore.
- This provides for reasonable translations of upper case acronyms, e.g., "theWWW" is translated to "the_www".
- An upper case character in the first position of the Java property
name is not preceded by an underscore character, and is translated only
to its lower case equivalent.
- For example, "Results" is translated to "results", and not to "_results".
- An upper case character in the Java property name that is already
preceded by an underscore character is translated only to its lower case
equivalent, and is not preceded by an additional underscore.
- For example, "user_Name" is translated to "user_name", and not to "user__name" (with two underscore characters).
- For contiguous sequences of upper case letters, characters after
the first character are replaced only by their lower case equivalent,
and are not preceded by an underscore.
- If the Java property name starts with an underscore, then that underscore is not included in the translated name, unless the Java property name is just one character in length, i.e., it is the underscore character. This applies only to the first character of the Java property name.
These rules result in the following additional example translations from Java property names to JSON element names.
- "userName" is translated to "user_name"
- "UserName" is translated to "user_name"
- "USER_NAME" is translated to "user_name"
- "user_name" is translated to "user_name" (unchanged)
- "user" is translated to "user" (unchanged)
- "User" is translated to "user"
- "USER" is translated to "user"
- "_user" is translated to "user"
- "_User" is translated to "user"
- "__user" is translated to "_user" (the first of two underscores was removed)
- "user__name" is translated to "user__name" (unchanged, with two underscores)
- See Also:
- Serialized Form
-
-
Nested Class Summary
-
Nested classes/interfaces inherited from class com.fasterxml.jackson.databind.PropertyNamingStrategy
PropertyNamingStrategy.KebabCaseStrategy, PropertyNamingStrategy.LowerCaseStrategy, PropertyNamingStrategy.LowerCaseWithUnderscoresStrategy, PropertyNamingStrategy.LowerDotCaseStrategy, PropertyNamingStrategy.PascalCaseStrategy, PropertyNamingStrategy.PropertyNamingStrategyBase, PropertyNamingStrategy.SnakeCaseStrategy, PropertyNamingStrategy.UpperCamelCaseStrategy
-
-
Field Summary
-
Fields inherited from class com.fasterxml.jackson.databind.PropertyNamingStrategy
CAMEL_CASE_TO_LOWER_CASE_WITH_UNDERSCORES, KEBAB_CASE, LOWER_CAMEL_CASE, LOWER_CASE, LOWER_DOT_CASE, PASCAL_CASE_TO_CAMEL_CASE, SNAKE_CASE, UPPER_CAMEL_CASE
-
-
Constructor Summary
Constructors Constructor Description SnakeCaseStrategy()
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description java.lang.String
translate(java.lang.String input)
-
Methods inherited from class com.fasterxml.jackson.databind.PropertyNamingStrategies.NamingBase
nameForConstructorParameter, nameForField, nameForGetterMethod, nameForSetterMethod
-
-
-
-
Method Detail
-
translate
public java.lang.String translate(java.lang.String input)
- Specified by:
translate
in classPropertyNamingStrategies.NamingBase
-
-