-
-
Notifications
You must be signed in to change notification settings - Fork 1.4k
Global enum naming strategy to use when it's not set directly on a class level #4716
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
0c9b315
9cd737e
b6da0d5
c6c92b0
e151a0d
109c22a
30f58cf
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -53,7 +53,7 @@ public abstract class MapperBuilder<M extends ObjectMapper, | |
|
||
protected final static BaseSettings DEFAULT_BASE_SETTINGS = new BaseSettings( | ||
DEFAULT_ANNOTATION_INTROSPECTOR, | ||
null, DEFAULT_ACCESSOR_NAMING, | ||
null, null, DEFAULT_ACCESSOR_NAMING, | ||
null, // no default typing, by default | ||
DEFAULT_TYPE_VALIDATOR, // and polymorphic type by class won't pass either | ||
StdDateFormat.instance, null, | ||
|
@@ -1236,6 +1236,21 @@ public B propertyNamingStrategy(PropertyNamingStrategy s) { | |
return _this(); | ||
} | ||
|
||
/** | ||
* Method for configuring {@link EnumNamingStrategy} to use for adapting | ||
* POJO enum names (internal) into content property names (external) | ||
* | ||
* @param s Strategy instance to use | ||
* | ||
* @return Builder instance itself to allow chaining | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. add |
||
* | ||
* @since 2.19 | ||
*/ | ||
public B enumNamingStrategy(EnumNamingStrategy s) { | ||
_baseSettings = _baseSettings.with(s); | ||
return _this(); | ||
} | ||
|
||
/** | ||
* Method for configuring {@link AccessorNamingStrategy} to use for auto-detecting | ||
* accessor ("getter") and mutator ("setter") methods based on naming of methods. | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -291,4 +291,17 @@ public void testEnumMixInDeserializationTest() throws Exception { | |
BaseEnum deser = mapper.readValue(q("realName"), BaseEnum.class); | ||
assertEquals(BaseEnum.REAL_NAME, deser); | ||
} | ||
|
||
@Test | ||
void testUseEnumMappingStrategySetInMapper() { | ||
ObjectMapper mapper = jsonMapperBuilder() | ||
.enumNamingStrategy(EnumNamingStrategies.CamelCaseStrategy.INSTANCE) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This seems awkward. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. No, I think strategy passed should be instance, not class. This is used for most configuration; mapper/builder not having to dynamically construct instances. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We could just ask for There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Ah, makes sense👍🏼 |
||
.build(); | ||
|
||
BaseEnum result = mapper.readValue(q("realName"), BaseEnum.class); | ||
assertEquals(BaseEnum.REAL_NAME, result); | ||
|
||
String resultString = mapper.writeValueAsString(result); | ||
assertEquals(q("realName"), resultString); | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please don't make source incompatible changes. Add a new constructor and deprecate the old one.