-
-
Notifications
You must be signed in to change notification settings - Fork 1.4k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
9f97baa
commit 1f58fdb
Showing
10 changed files
with
153 additions
and
172 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -30,41 +30,53 @@ public abstract class PropertyNamingStrategies | |
* and no separator is used between words. Since this is the native Java naming convention, | ||
* naming strategy will not do any transformation between names in data (JSON) and | ||
* POJOS. | ||
*<p> | ||
* Example external property names would be "numberValue", "namingStrategy", "theDefiniteProof". | ||
*/ | ||
public static final PropertyNamingStrategy LOWER_CAMEL_CASE = new PropertyNamingStrategy(); | ||
public static final PropertyNamingStrategy LOWER_CAMEL_CASE = new LowerCamelCaseStrategy(); | ||
|
||
/** | ||
* Naming convention used in languages like Pascal, where words are capitalized | ||
* Naming convention used in languages like Pascal, where all words are capitalized | ||
* and no separator is used between words. | ||
* See {@link UpperCamelCaseStrategy} for details. | ||
*<p> | ||
* Example external property names would be "NumberValue", "NamingStrategy", "TheDefiniteProof". | ||
*/ | ||
public static final PropertyNamingStrategy UPPER_CAMEL_CASE = new UpperCamelCaseStrategy(); | ||
|
||
/** | ||
* Naming convention used in languages like C, where words are in lower-case | ||
* letters, separated by underscores. | ||
* See {@link SnakeCaseStrategy} for details. | ||
*<p> | ||
* Example external property names would be "number_value", "naming_strategy", "the_definite_proof". | ||
*/ | ||
public static final PropertyNamingStrategy SNAKE_CASE = new SnakeCaseStrategy(); | ||
|
||
/** | ||
* Naming convention in which all words of the logical name are in lower case, and | ||
* no separator is used between words. | ||
* See {@link LowerCaseStrategy} for details. | ||
*<p> | ||
* Example external property names would be "numbervalue", "namingstrategy", "thedefiniteproof". | ||
*/ | ||
public static final PropertyNamingStrategy LOWER_CASE = new LowerCaseStrategy(); | ||
|
||
/** | ||
* Naming convention used in languages like Lisp, where words are in lower-case | ||
* letters, separated by hyphens. | ||
* See {@link KebabCaseStrategy} for details. | ||
*<p> | ||
* Example external property names would be "number-value", "naming-strategy", "the-definite-proof". | ||
*/ | ||
public static final PropertyNamingStrategy KEBAB_CASE = new KebabCaseStrategy(); | ||
|
||
/** | ||
* Naming convention widely used as configuration properties name, where words are in | ||
* lower-case letters, separated by dots. | ||
* See {@link LowerDotCaseStrategy} for details. | ||
*<p> | ||
* Example external property names would be "number.value", "naming.strategy", "the.definite.proof". | ||
*/ | ||
public static final PropertyNamingStrategy LOWER_DOT_CASE = new LowerDotCaseStrategy(); | ||
|
||
|
@@ -77,7 +89,7 @@ public abstract class PropertyNamingStrategies | |
/** | ||
* Intermediate base class for simple implementations | ||
*/ | ||
static abstract class NamingBase | ||
public static abstract class NamingBase | ||
This comment has been minimized.
Sorry, something went wrong.
This comment has been minimized.
Sorry, something went wrong.
yawkat
Member
|
||
extends PropertyNamingStrategy | ||
{ | ||
private static final long serialVersionUID = 2L; | ||
|
@@ -152,39 +164,39 @@ protected String translateLowerCaseWithSeparator(final String input, final char | |
*/ | ||
|
||
/** | ||
* A {@link PropertyNamingStrategy} 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 | ||
* A {@link PropertyNamingStrategy} 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. | ||
* | ||
* <ul><li>Every upper case letter in the Java property name is translated | ||
* into two characters, an underscore and the lower case equivalent of the | ||
* <ul><li>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. | ||
* <ol><li>For contiguous sequences of upper case letters, characters after | ||
* the first character are replaced only by their lower case equivalent, | ||
* the first character are replaced only by their lower case equivalent, | ||
* and are not preceded by an underscore. | ||
* <ul><li>This provides for reasonable translations of upper case acronyms, | ||
* e.g., "theWWW" is translated to "the_www".</li></ul></li> | ||
* <li>An upper case character in the first position of the Java property | ||
* name is not preceded by an underscore character, and is translated only | ||
* <ul><li>This provides for reasonable translations of upper case acronyms, | ||
* e.g., "theWWW" is translated to "the_www".</li></ul></li | ||
* <li>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. | ||
* <ul><li>For example, "Results" is translated to "results", | ||
* <ul><li>For example, "Results" is translated to "results", | ||
* and not to "_results".</li></ul></li> | ||
* <li>An upper case character in the Java property name that is already | ||
* preceded by an underscore character is translated only to its lower case | ||
* <li>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. | ||
* <ul><li>For example, "user_Name" is translated to | ||
* "user_name", and not to "user__name" (with two | ||
* <ul><li>For example, "user_Name" is translated to | ||
* "user_name", and not to "user__name" (with two | ||
* underscore characters).</li></ul></li></ol></li> | ||
* <li>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 | ||
* <li>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.</li></ul> | ||
* | ||
* These rules result in the following additional example translations from | ||
*<p> | ||
* These rules result in the following additional example translations from | ||
* Java property names to JSON element names. | ||
* <ul><li>"userName" is translated to "user_name"</li> | ||
* <li>"UserName" is translated to "user_name"</li> | ||
|
@@ -239,6 +251,20 @@ public String translate(String input) | |
} | ||
} | ||
|
||
/** | ||
* "No-operation" strategy that is equivalent to not specifying any | ||
* strategy: will simply return suggested standard bean naming as-is. | ||
*/ | ||
public static class LowerCamelCaseStrategy extends NamingBase | ||
{ | ||
private static final long serialVersionUID = 2L; | ||
|
||
@Override | ||
public String translate(String input) { | ||
return input; | ||
} | ||
} | ||
|
||
/** | ||
* A {@link PropertyNamingStrategy} that translates typical camelCase Java | ||
* property names to PascalCase JSON element names (i.e., with a capital | ||
|
Oops, something went wrong.
Making this
public
makes it a drop-in replacement forPropertyNamingStrategy.PropertyNamingStrategyBase
. Does it not have the same problem as described in #2715? Or is there something I'm missing that makes this class safe to use where the other (deprecated) one is not?