Skip to content

Commit 1f58fdb

Browse files
committed
Fixed #2715
1 parent 9f97baa commit 1f58fdb

File tree

10 files changed

+153
-172
lines changed

10 files changed

+153
-172
lines changed

release-notes/VERSION-2.x

+3
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,9 @@ Project: jackson-databind
4343
#2707: Improve description included in by `DeserializationContext.handleUnexpectedToken()`
4444
#2709: Support for JDK 14 record types (`java.lang.Record`)
4545
(contributed by Youri B)
46+
#2715: `PropertyNamingStrategy` class initialization depends on its subclass, this can
47+
lead to class loading deadlock
48+
(reported by fangwentong@github)
4649
#2719: `FAIL_ON_IGNORED_PROPERTIES` does not throw on `READONLY` properties with
4750
an explicit name
4851
(reported, fix contributed by David B)

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

+52-26
Original file line numberDiff line numberDiff line change
@@ -30,41 +30,53 @@ public abstract class PropertyNamingStrategies
3030
* and no separator is used between words. Since this is the native Java naming convention,
3131
* naming strategy will not do any transformation between names in data (JSON) and
3232
* POJOS.
33+
*<p>
34+
* Example external property names would be "numberValue", "namingStrategy", "theDefiniteProof".
3335
*/
34-
public static final PropertyNamingStrategy LOWER_CAMEL_CASE = new PropertyNamingStrategy();
36+
public static final PropertyNamingStrategy LOWER_CAMEL_CASE = new LowerCamelCaseStrategy();
3537

3638
/**
37-
* Naming convention used in languages like Pascal, where words are capitalized
39+
* Naming convention used in languages like Pascal, where all words are capitalized
3840
* and no separator is used between words.
3941
* See {@link UpperCamelCaseStrategy} for details.
42+
*<p>
43+
* Example external property names would be "NumberValue", "NamingStrategy", "TheDefiniteProof".
4044
*/
4145
public static final PropertyNamingStrategy UPPER_CAMEL_CASE = new UpperCamelCaseStrategy();
4246

4347
/**
4448
* Naming convention used in languages like C, where words are in lower-case
4549
* letters, separated by underscores.
4650
* See {@link SnakeCaseStrategy} for details.
51+
*<p>
52+
* Example external property names would be "number_value", "naming_strategy", "the_definite_proof".
4753
*/
4854
public static final PropertyNamingStrategy SNAKE_CASE = new SnakeCaseStrategy();
4955

5056
/**
5157
* Naming convention in which all words of the logical name are in lower case, and
5258
* no separator is used between words.
5359
* See {@link LowerCaseStrategy} for details.
60+
*<p>
61+
* Example external property names would be "numbervalue", "namingstrategy", "thedefiniteproof".
5462
*/
5563
public static final PropertyNamingStrategy LOWER_CASE = new LowerCaseStrategy();
5664

5765
/**
5866
* Naming convention used in languages like Lisp, where words are in lower-case
5967
* letters, separated by hyphens.
6068
* See {@link KebabCaseStrategy} for details.
69+
*<p>
70+
* Example external property names would be "number-value", "naming-strategy", "the-definite-proof".
6171
*/
6272
public static final PropertyNamingStrategy KEBAB_CASE = new KebabCaseStrategy();
6373

6474
/**
6575
* Naming convention widely used as configuration properties name, where words are in
6676
* lower-case letters, separated by dots.
6777
* See {@link LowerDotCaseStrategy} for details.
78+
*<p>
79+
* Example external property names would be "number.value", "naming.strategy", "the.definite.proof".
6880
*/
6981
public static final PropertyNamingStrategy LOWER_DOT_CASE = new LowerDotCaseStrategy();
7082

@@ -77,7 +89,7 @@ public abstract class PropertyNamingStrategies
7789
/**
7890
* Intermediate base class for simple implementations
7991
*/
80-
static abstract class NamingBase
92+
public static abstract class NamingBase
8193
extends PropertyNamingStrategy
8294
{
8395
private static final long serialVersionUID = 2L;
@@ -152,39 +164,39 @@ protected String translateLowerCaseWithSeparator(final String input, final char
152164
*/
153165

154166
/**
155-
* A {@link PropertyNamingStrategy} that translates typical camel case Java
156-
* property names to lower case JSON element names, separated by
157-
* underscores. This implementation is somewhat lenient, in that it
158-
* provides some additional translations beyond strictly translating from
159-
* camel case only. In particular, the following translations are applied
167+
* A {@link PropertyNamingStrategy} that translates typical camel case Java
168+
* property names to lower case JSON element names, separated by
169+
* underscores. This implementation is somewhat lenient, in that it
170+
* provides some additional translations beyond strictly translating from
171+
* camel case only. In particular, the following translations are applied
160172
* by this PropertyNamingStrategy.
161173
*
162-
* <ul><li>Every upper case letter in the Java property name is translated
163-
* into two characters, an underscore and the lower case equivalent of the
174+
* <ul><li>Every upper case letter in the Java property name is translated
175+
* into two characters, an underscore and the lower case equivalent of the
164176
* target character, with three exceptions.
165177
* <ol><li>For contiguous sequences of upper case letters, characters after
166-
* the first character are replaced only by their lower case equivalent,
178+
* the first character are replaced only by their lower case equivalent,
167179
* and are not preceded by an underscore.
168-
* <ul><li>This provides for reasonable translations of upper case acronyms,
169-
* e.g., &quot;theWWW&quot; is translated to &quot;the_www&quot;.</li></ul></li>
170-
* <li>An upper case character in the first position of the Java property
171-
* name is not preceded by an underscore character, and is translated only
180+
* <ul><li>This provides for reasonable translations of upper case acronyms,
181+
* e.g., &quot;theWWW&quot; is translated to &quot;the_www&quot;.</li></ul></li
182+
* <li>An upper case character in the first position of the Java property
183+
* name is not preceded by an underscore character, and is translated only
172184
* to its lower case equivalent.
173-
* <ul><li>For example, &quot;Results&quot; is translated to &quot;results&quot;,
185+
* <ul><li>For example, &quot;Results&quot; is translated to &quot;results&quot;,
174186
* and not to &quot;_results&quot;.</li></ul></li>
175-
* <li>An upper case character in the Java property name that is already
176-
* preceded by an underscore character is translated only to its lower case
187+
* <li>An upper case character in the Java property name that is already
188+
* preceded by an underscore character is translated only to its lower case
177189
* equivalent, and is not preceded by an additional underscore.
178-
* <ul><li>For example, &quot;user_Name&quot; is translated to
179-
* &quot;user_name&quot;, and not to &quot;user__name&quot; (with two
190+
* <ul><li>For example, &quot;user_Name&quot; is translated to
191+
* &quot;user_name&quot;, and not to &quot;user__name&quot; (with two
180192
* underscore characters).</li></ul></li></ol></li>
181-
* <li>If the Java property name starts with an underscore, then that
182-
* underscore is not included in the translated name, unless the Java
183-
* property name is just one character in length, i.e., it is the
184-
* underscore character. This applies only to the first character of the
193+
* <li>If the Java property name starts with an underscore, then that
194+
* underscore is not included in the translated name, unless the Java
195+
* property name is just one character in length, i.e., it is the
196+
* underscore character. This applies only to the first character of the
185197
* Java property name.</li></ul>
186-
*
187-
* These rules result in the following additional example translations from
198+
*<p>
199+
* These rules result in the following additional example translations from
188200
* Java property names to JSON element names.
189201
* <ul><li>&quot;userName&quot; is translated to &quot;user_name&quot;</li>
190202
* <li>&quot;UserName&quot; is translated to &quot;user_name&quot;</li>
@@ -239,6 +251,20 @@ public String translate(String input)
239251
}
240252
}
241253

254+
/**
255+
* "No-operation" strategy that is equivalent to not specifying any
256+
* strategy: will simply return suggested standard bean naming as-is.
257+
*/
258+
public static class LowerCamelCaseStrategy extends NamingBase
259+
{
260+
private static final long serialVersionUID = 2L;
261+
262+
@Override
263+
public String translate(String input) {
264+
return input;
265+
}
266+
}
267+
242268
/**
243269
* A {@link PropertyNamingStrategy} that translates typical camelCase Java
244270
* property names to PascalCase JSON element names (i.e., with a capital

0 commit comments

Comments
 (0)