Skip to content

Commit

Permalink
Fixed #2715
Browse files Browse the repository at this point in the history
  • Loading branch information
cowtowncoder committed Aug 25, 2020
1 parent 9f97baa commit 1f58fdb
Show file tree
Hide file tree
Showing 10 changed files with 153 additions and 172 deletions.
3 changes: 3 additions & 0 deletions release-notes/VERSION-2.x
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,9 @@ Project: jackson-databind
#2707: Improve description included in by `DeserializationContext.handleUnexpectedToken()`
#2709: Support for JDK 14 record types (`java.lang.Record`)
(contributed by Youri B)
#2715: `PropertyNamingStrategy` class initialization depends on its subclass, this can
lead to class loading deadlock
(reported by fangwentong@github)
#2719: `FAIL_ON_IGNORED_PROPERTIES` does not throw on `READONLY` properties with
an explicit name
(reported, fix contributed by David B)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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();

Expand All @@ -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.

Copy link
@bschelberg

bschelberg May 26, 2022

Making this public makes it a drop-in replacement for PropertyNamingStrategy.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?

This comment has been minimized.

Copy link
@yawkat

yawkat May 26, 2022

Member

PropertyNamingStrategy does not depend on PropertyNamingStrategies.NamingBase, so there is no deadlock.

This comment has been minimized.

Copy link
@bschelberg

bschelberg May 26, 2022

Ohhh, I get it now. Thanks for clarifying that.

extends PropertyNamingStrategy
{
private static final long serialVersionUID = 2L;
Expand Down Expand Up @@ -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., &quot;theWWW&quot; is translated to &quot;the_www&quot;.</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., &quot;theWWW&quot; is translated to &quot;the_www&quot;.</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, &quot;Results&quot; is translated to &quot;results&quot;,
* <ul><li>For example, &quot;Results&quot; is translated to &quot;results&quot;,
* and not to &quot;_results&quot;.</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, &quot;user_Name&quot; is translated to
* &quot;user_name&quot;, and not to &quot;user__name&quot; (with two
* <ul><li>For example, &quot;user_Name&quot; is translated to
* &quot;user_name&quot;, and not to &quot;user__name&quot; (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>&quot;userName&quot; is translated to &quot;user_name&quot;</li>
* <li>&quot;UserName&quot; is translated to &quot;user_name&quot;</li>
Expand Down Expand Up @@ -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
Expand Down
Loading

0 comments on commit 1f58fdb

Please sign in to comment.