Skip to content

Commit cebfddb

Browse files
committed
Fixed #909
1 parent 441f20c commit cebfddb

File tree

3 files changed

+65
-13
lines changed

3 files changed

+65
-13
lines changed

release-notes/VERSION

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,9 @@ Project: jackson-databind
1919
#898: Add `ObjectMapper.getSerializerProviderInstance()`
2020
#905: Add support for `@ConstructorProperties`
2121
(requested by Jonas K)
22+
#909: Rename PropertyNamingStrategy CAMEL_CASE_TO_LOWER_CASE_WITH_UNDERSCORES as SNAKE_CASE,
23+
PASCAL_CASE_TO_CAMEL_CASE as UPPER_CAMEL_CASE
24+
(suggested by marcottedan@github)
2225
#915: ObjectMapper default timezone is GMT, should be UTC
2326
(suggested by Infrag@github)
2427
#918: Add `MapperFeature.ALLOW_EXPLICIT_PROPERTY_RENAMING`

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

Lines changed: 60 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -27,24 +27,40 @@
2727
* characters).
2828
*/
2929
@SuppressWarnings("serial")
30-
public abstract class PropertyNamingStrategy
30+
public class PropertyNamingStrategy // NOTE: was abstract until 2.7
3131
implements java.io.Serializable
3232
{
3333
/**
34-
* See {@link LowerCaseWithUnderscoresStrategy} for details.
34+
* Naming convention used in languages like C, where words are in lower-case
35+
* letters, separated by underscores.
36+
* See {@link SnakeCaseStrategy} for details.
37+
*
38+
* @since 2.7 (was formerly called {@link #CAMEL_CASE_TO_LOWER_CASE_WITH_UNDERSCORES})
3539
*/
36-
public static final PropertyNamingStrategy CAMEL_CASE_TO_LOWER_CASE_WITH_UNDERSCORES =
37-
new LowerCaseWithUnderscoresStrategy();
40+
public static final PropertyNamingStrategy SNAKE_CASE = new SnakeCaseStrategy();
3841

3942
/**
43+
* Naming convention used in languages like Pascal, where words are capitalized
44+
* and no separator is used between words.
4045
* See {@link PascalCaseStrategy} for details.
41-
*
42-
* @since 2.1
46+
*
47+
* @since 2.7 (was formerly called {@link #PASCAL_CASE_TO_CAMEL_CASE})
4348
*/
44-
public static final PropertyNamingStrategy PASCAL_CASE_TO_CAMEL_CASE =
45-
new PascalCaseStrategy();
49+
public static final PropertyNamingStrategy UPPER_CAMEL_CASE = new UpperCamelCaseStrategy();
4650

4751
/**
52+
* Naming convention used in Java, where words other than first are capitalized
53+
* and no separator is used between words. Since this is the native Java naming convention,
54+
* naming strategy will not do any transformation between names in data (JSON) and
55+
* POJOS.
56+
*
57+
* @since 2.7 (was formerly called {@link #PASCAL_CASE_TO_CAMEL_CASE})
58+
*/
59+
public static final PropertyNamingStrategy LOWER_CAMEL_CASE = new PropertyNamingStrategy();
60+
61+
/**
62+
* Naming convention in which all words of the logical name are in lower case, and
63+
* no separator is used between words.
4864
* See {@link LowerCaseStrategy} for details.
4965
*
5066
* @since 2.4
@@ -226,8 +242,10 @@ public String nameForConstructorParameter(MapperConfig<?> config, AnnotatedParam
226242
* (the first of two underscores was removed)</li>
227243
* <li>&quot;user__name&quot; is translated to &quot;user__name&quot;
228244
* (unchanged, with two underscores)</li></ul>
245+
*
246+
* @since 2.7 (was previously called }
229247
*/
230-
public static class LowerCaseWithUnderscoresStrategy extends PropertyNamingStrategyBase
248+
public static class SnakeCaseStrategy extends PropertyNamingStrategyBase
231249
{
232250
@Override
233251
public String translate(String input)
@@ -277,9 +295,9 @@ public String translate(String input)
277295
* Java property names to JSON element names.
278296
* <ul><li>&quot;userName&quot; is translated to &quot;UserName&quot;</li></ul>
279297
*
280-
* @since 2.1
298+
* @since 2.7 (was formerly called {@link PascalCaseStrategy})
281299
*/
282-
public static class PascalCaseStrategy extends PropertyNamingStrategyBase
300+
public static class UpperCamelCaseStrategy extends PropertyNamingStrategyBase
283301
{
284302
/**
285303
* Converts camelCase to PascalCase
@@ -322,4 +340,35 @@ public String translate(String input) {
322340
return input.toLowerCase();
323341
}
324342
}
343+
344+
/*
345+
/**********************************************************
346+
/* Deprecated variants, aliases
347+
/**********************************************************
348+
*/
349+
350+
/**
351+
* @deprecated Since 2.7 use {@link #SNAKE_CASE} instead;
352+
*/
353+
@Deprecated // since 2.7
354+
public static final PropertyNamingStrategy CAMEL_CASE_TO_LOWER_CASE_WITH_UNDERSCORES = SNAKE_CASE;
355+
356+
/**
357+
* @deprecated Since 2.7 use {@link #UPPER_CAMEL_CASE} instead;
358+
*/
359+
@Deprecated // since 2.7
360+
public static final PropertyNamingStrategy PASCAL_CASE_TO_CAMEL_CASE = UPPER_CAMEL_CASE;
361+
362+
/**
363+
* @deprecated In 2.7 use {@link SnakeCaseStrategy} instead
364+
*/
365+
@Deprecated
366+
public static class LowerCaseWithUnderscoresStrategy extends SnakeCaseStrategy {}
367+
368+
/**
369+
* @deprecated In 2.7 use {@link SnakeCaseStrategy} instead
370+
*/
371+
@Deprecated
372+
public static class PascalCaseStrategy extends UpperCamelCaseStrategy {}
325373
}
374+

src/main/java/com/fasterxml/jackson/databind/introspect/JacksonAnnotationIntrospector.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -224,14 +224,14 @@ public Object findNamingStrategy(AnnotatedClass ac)
224224
{
225225
JsonNaming ann = _findAnnotation(ac, JsonNaming.class);
226226
return (ann == null) ? null : ann.value();
227-
}
227+
}
228228

229229
/*
230230
/**********************************************************
231231
/* Property auto-detection
232232
/**********************************************************
233233
*/
234-
234+
235235
@Override
236236
public VisibilityChecker<?> findAutoDetectVisibility(AnnotatedClass ac,
237237
VisibilityChecker<?> checker)

0 commit comments

Comments
 (0)