Skip to content

Commit 0569cca

Browse files
authored
Fix #3633: expose typed instances of standard PropertyNamingStrategy instances. (#3641)
1 parent 1e09695 commit 0569cca

File tree

3 files changed

+60
-9
lines changed

3 files changed

+60
-9
lines changed

release-notes/CREDITS-2.x

+5
Original file line numberDiff line numberDiff line change
@@ -1507,3 +1507,8 @@ Richard Kwasnicki (Richie94@github)
15071507
* Contributed #3609: Allow non-boolean return type for "is-getters" with
15081508
`MapperFeature.ALLOW_IS_GETTERS_FOR_NON_BOOLEAN`
15091509
(2.14.0)
1510+
1511+
Joachim Durchholz (toolforger@github)
1512+
* Requested #3633: Expose `translate()` method of standard `PropertyNamingStrategy`
1513+
implementations
1514+
(2.14.0)

release-notes/VERSION-2.x

+3-1
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,9 @@ Not yet released:
1111
(contributed by Felix V)
1212
#3624: Legacy `ALLOW_COERCION_OF_SCALARS` interacts poorly with Integer to
1313
Float coercion
14-
(contributed by Carter K)
14+
(contributed by Carter K)
15+
#3633: Expose `translate()` method of standard `PropertyNamingStrategy` implementations
16+
(requested by Joachim D)
1517

1618
2.14.0-rc2 (10-Oct-2022)
1719

src/main/java/com/fasterxml/jackson/databind/PropertyNamingStrategies.java

+52-8
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ public abstract class PropertyNamingStrategies
3333
*<p>
3434
* Example external property names would be "numberValue", "namingStrategy", "theDefiniteProof".
3535
*/
36-
public static final PropertyNamingStrategy LOWER_CAMEL_CASE = new LowerCamelCaseStrategy();
36+
public static final PropertyNamingStrategy LOWER_CAMEL_CASE = LowerCamelCaseStrategy.INSTANCE;
3737

3838
/**
3939
* Naming convention used in languages like Pascal, where all words are capitalized
@@ -42,7 +42,7 @@ public abstract class PropertyNamingStrategies
4242
*<p>
4343
* Example external property names would be "NumberValue", "NamingStrategy", "TheDefiniteProof".
4444
*/
45-
public static final PropertyNamingStrategy UPPER_CAMEL_CASE = new UpperCamelCaseStrategy();
45+
public static final PropertyNamingStrategy UPPER_CAMEL_CASE = UpperCamelCaseStrategy.INSTANCE;
4646

4747
/**
4848
* Naming convention used in languages like C, where words are in lower-case
@@ -51,15 +51,15 @@ public abstract class PropertyNamingStrategies
5151
*<p>
5252
* Example external property names would be "number_value", "naming_strategy", "the_definite_proof".
5353
*/
54-
public static final PropertyNamingStrategy SNAKE_CASE = new SnakeCaseStrategy();
54+
public static final PropertyNamingStrategy SNAKE_CASE = SnakeCaseStrategy.INSTANCE;
5555

5656
/**
5757
* Naming convention in which the words are in upper-case letters, separated by underscores.
5858
* See {@link UpperSnakeCaseStrategy} for details.
5959
* @since 2.13
6060
* <p>
6161
*/
62-
public static final PropertyNamingStrategy UPPER_SNAKE_CASE = new UpperSnakeCaseStrategy();
62+
public static final PropertyNamingStrategy UPPER_SNAKE_CASE = UpperSnakeCaseStrategy.INSTANCE;
6363

6464
/**
6565
* Naming convention in which all words of the logical name are in lower case, and
@@ -68,7 +68,7 @@ public abstract class PropertyNamingStrategies
6868
*<p>
6969
* Example external property names would be "numbervalue", "namingstrategy", "thedefiniteproof".
7070
*/
71-
public static final PropertyNamingStrategy LOWER_CASE = new LowerCaseStrategy();
71+
public static final PropertyNamingStrategy LOWER_CASE = LowerCaseStrategy.INSTANCE;
7272

7373
/**
7474
* Naming convention used in languages like Lisp, where words are in lower-case
@@ -77,7 +77,7 @@ public abstract class PropertyNamingStrategies
7777
*<p>
7878
* Example external property names would be "number-value", "naming-strategy", "the-definite-proof".
7979
*/
80-
public static final PropertyNamingStrategy KEBAB_CASE = new KebabCaseStrategy();
80+
public static final PropertyNamingStrategy KEBAB_CASE = KebabCaseStrategy.INSTANCE;
8181

8282
/**
8383
* Naming convention widely used as configuration properties name, where words are in
@@ -86,7 +86,7 @@ public abstract class PropertyNamingStrategies
8686
*<p>
8787
* Example external property names would be "number.value", "naming.strategy", "the.definite.proof".
8888
*/
89-
public static final PropertyNamingStrategy LOWER_DOT_CASE = new LowerDotCaseStrategy();
89+
public static final PropertyNamingStrategy LOWER_DOT_CASE = LowerDotCaseStrategy.INSTANCE;
9090

9191
/*
9292
/**********************************************************************
@@ -224,6 +224,12 @@ public static class SnakeCaseStrategy extends NamingBase
224224
{
225225
private static final long serialVersionUID = 2L;
226226

227+
/**
228+
* @since 2.14
229+
*/
230+
public final static PropertyNamingStrategies.SnakeCaseStrategy INSTANCE
231+
= new PropertyNamingStrategies.SnakeCaseStrategy();
232+
227233
@Override
228234
public String translate(String input)
229235
{
@@ -270,6 +276,12 @@ public static class UpperSnakeCaseStrategy extends SnakeCaseStrategy
270276
{
271277
private static final long serialVersionUID = 2L;
272278

279+
/**
280+
* @since 2.14
281+
*/
282+
public final static PropertyNamingStrategies.UpperSnakeCaseStrategy INSTANCE
283+
= new PropertyNamingStrategies.UpperSnakeCaseStrategy();
284+
273285
@Override
274286
public String translate(String input) {
275287
String output = super.translate(input);
@@ -287,6 +299,12 @@ public static class LowerCamelCaseStrategy extends NamingBase
287299
{
288300
private static final long serialVersionUID = 2L;
289301

302+
/**
303+
* @since 2.14
304+
*/
305+
public final static PropertyNamingStrategies.LowerCamelCaseStrategy INSTANCE
306+
= new PropertyNamingStrategies.LowerCamelCaseStrategy();
307+
290308
@Override
291309
public String translate(String input) {
292310
return input;
@@ -310,6 +328,12 @@ public static class UpperCamelCaseStrategy extends NamingBase
310328
{
311329
private static final long serialVersionUID = 2L;
312330

331+
/**
332+
* @since 2.14
333+
*/
334+
public final static PropertyNamingStrategies.UpperCamelCaseStrategy INSTANCE
335+
= new PropertyNamingStrategies.UpperCamelCaseStrategy();
336+
313337
/**
314338
* Converts camelCase to PascalCase
315339
*
@@ -346,6 +370,12 @@ public static class LowerCaseStrategy extends NamingBase
346370
{
347371
private static final long serialVersionUID = 2L;
348372

373+
/**
374+
* @since 2.14
375+
*/
376+
public final static PropertyNamingStrategies.LowerCaseStrategy INSTANCE
377+
= new PropertyNamingStrategies.LowerCaseStrategy();
378+
349379
@Override
350380
public String translate(String input) {
351381
return input.toLowerCase();
@@ -362,6 +392,12 @@ public static class KebabCaseStrategy extends NamingBase
362392
{
363393
private static final long serialVersionUID = 2L;
364394

395+
/**
396+
* @since 2.14
397+
*/
398+
public final static PropertyNamingStrategies.KebabCaseStrategy INSTANCE
399+
= new PropertyNamingStrategies.KebabCaseStrategy();
400+
365401
@Override
366402
public String translate(String input) {
367403
return translateLowerCaseWithSeparator(input, '-');
@@ -373,12 +409,20 @@ public String translate(String input) {
373409
* but instead of hyphens
374410
* as separators, uses dots. Naming convention widely used as configuration properties name.
375411
*/
376-
public static class LowerDotCaseStrategy extends NamingBase {
412+
public static class LowerDotCaseStrategy extends NamingBase
413+
{
377414
private static final long serialVersionUID = 2L;
378415

416+
/**
417+
* @since 2.14
418+
*/
419+
public final static PropertyNamingStrategies.LowerDotCaseStrategy INSTANCE
420+
= new PropertyNamingStrategies.LowerDotCaseStrategy();
421+
379422
@Override
380423
public String translate(String input){
381424
return translateLowerCaseWithSeparator(input, '.');
382425
}
383426
}
384427
}
428+

0 commit comments

Comments
 (0)