Skip to content

Commit

Permalink
Minor post-merge clean up for #2787
Browse files Browse the repository at this point in the history
  • Loading branch information
cowtowncoder committed Jun 16, 2023
1 parent e43b65d commit b08f622
Show file tree
Hide file tree
Showing 5 changed files with 35 additions and 22 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -1097,7 +1097,10 @@ public Boolean hasAnyGetter(Annotated ann) {
* @return Array of names to use (possible {@code names} passed as argument)
*
* @since 2.7
*
* @deprecated Since 2.16
*/
@Deprecated
public String[] findEnumValues(Class<?> enumType, Enum<?>[] enumValues, String[] names) {
// 18-Oct-2016, tatu: In 2.8 delegated to deprecated method; not so in 2.9 and beyond
return names;
Expand All @@ -1109,17 +1112,17 @@ public String[] findEnumValues(Class<?> enumType, Enum<?>[] enumValues, String[]
* names found, if any, leaving other entries unmodified.
*
* @param config the mapper configuration to use
* @param annotatedClass the annotated class for which to find the explicit names
* @param enumValues the set of {@code Enum} values to find the explicit names for
* @param names the matching declared names of enumeration values (with indexes matching
* {@code enumValues} entries)
* @param annotatedClass the annotated class for which to find the explicit names
*
* @return an array of names to use (possibly {@code names} passed as argument)
*
* @since 2.16
*/
public String[] findEnumValues(MapperConfig<?> config, Enum<?>[] enumValues, String[] names,
AnnotatedClass annotatedClass){
public String[] findEnumValues(MapperConfig<?> config, AnnotatedClass annotatedClass,
Enum<?>[] enumValues, String[] names) {
return names;
}

Expand All @@ -1136,30 +1139,33 @@ public String[] findEnumValues(MapperConfig<?> config, Enum<?>[] enumValues, Str
* added (in indexes matching those of {@code enumValues})
*
* @since 2.11
*
* @deprecated Since 2.16
*/
@Deprecated
public void findEnumAliases(Class<?> enumType, Enum<?>[] enumValues, String[][] aliases) {
;
}


/**
* Method that is called to check if there are alternative names (aliases) that can be accepted for entries
* in addition to primary names that were introspected earlier, related to {@link #findEnumValues}.
* These aliases should be returned in {@code String[][] aliases} passed in as argument.
* The {@code aliases.length} is expected to match the number of {@code Enum} values.
*
* @param config The configuration of the mapper
* @param annotatedClass The annotated class of the enumeration type
* @param enumValues The values of the enumeration
* @param aliases (in/out) Pre-allocated array where aliases found, if any, may be added (in indexes
* matching those of {@code enumValues})
* @param annotatedClass The annotated class of the enumeration type
*
* @since 2.16
*/
public void findEnumAliases(MapperConfig<?> config, Enum<?>[] enumValues, String[][] aliases,
AnnotatedClass annotatedClass) {
public void findEnumAliases(MapperConfig<?> config, AnnotatedClass annotatedClass,
Enum<?>[] enumValues, String[][] aliases) {
return;
}

/**
* Finds the Enum value that should be considered the default value, if possible.
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -617,6 +617,7 @@ public Boolean hasAnyGetter(Annotated a) {
return b;
}

@Deprecated // since 2.16
@Override
public String[] findEnumValues(Class<?> enumType, Enum<?>[] enumValues, String[] names) {
// reverse order to give _primary higher precedence
Expand All @@ -626,13 +627,15 @@ public String[] findEnumValues(Class<?> enumType, Enum<?>[] enumValues, String[
}

@Override
public String[] findEnumValues(MapperConfig<?> config, Enum<?>[] enumValues, String[] names,
AnnotatedClass annotatedClass) {
names = _secondary.findEnumValues(config, enumValues, names, annotatedClass);
names = _primary.findEnumValues(config, enumValues, names, annotatedClass);
public String[] findEnumValues(MapperConfig<?> config, AnnotatedClass annotatedClass,
Enum<?>[] enumValues, String[] names) {
// reverse order to give _primary higher precedence
names = _secondary.findEnumValues(config, annotatedClass, enumValues, names);
names = _primary.findEnumValues(config, annotatedClass, enumValues, names);
return names;
}

@Deprecated // since 2.16
@Override
public void findEnumAliases(Class<?> enumType, Enum<?>[] enumValues, String[][] aliases) {
// reverse order to give _primary higher precedence
Expand All @@ -641,10 +644,11 @@ public void findEnumAliases(Class<?> enumType, Enum<?>[] enumValues, String[][]
}

@Override
public void findEnumAliases(MapperConfig<?> config, Enum<?>[] enumConstants, String[][] aliases,
AnnotatedClass annotatedClass) {
_secondary.findEnumAliases(config, enumConstants, aliases, annotatedClass);
_primary.findEnumAliases(config, enumConstants, aliases, annotatedClass);
public void findEnumAliases(MapperConfig<?> config, AnnotatedClass annotatedClass,
Enum<?>[] enumConstants, String[][] aliases) {
// reverse order to give _primary higher precedence
_secondary.findEnumAliases(config, annotatedClass, enumConstants, aliases);
_primary.findEnumAliases(config, annotatedClass, enumConstants, aliases);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -241,8 +241,9 @@ public String[] findEnumValues(Class<?> enumType, Enum<?>[] enumValues, String[]
}

@Override // since 2.16
public String[] findEnumValues(MapperConfig<?> config, Enum<?>[] enumValues, String[] names,
AnnotatedClass annotatedClass) {
public String[] findEnumValues(MapperConfig<?> config, AnnotatedClass annotatedClass,
Enum<?>[] enumValues, String[] names)
{
Map<String, String> enumToPropertyMap = new LinkedHashMap<String, String>();
for (AnnotatedField field : annotatedClass.fields()) {
JsonProperty property = field.getAnnotation(JsonProperty.class);
Expand Down Expand Up @@ -290,7 +291,8 @@ public void findEnumAliases(Class<?> enumType, Enum<?>[] enumValues, String[][]
}

@Override
public void findEnumAliases(MapperConfig<?> config, Enum<?>[] enumValues, String[][] aliasList, AnnotatedClass annotatedClass)
public void findEnumAliases(MapperConfig<?> config, AnnotatedClass annotatedClass,
Enum<?>[] enumValues, String[][] aliasList)
{
HashMap<String, String[]> enumToAliasMap = new HashMap<>();
for (AnnotatedField field : annotatedClass.fields()) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -147,9 +147,10 @@ public static EnumResolver _constructFor(DeserializationConfig config, Annotated
final Enum<?>[] enumConstants = _enumConstants(enumCls0);

// introspect
String[] names = ai.findEnumValues(config, enumConstants, new String[enumConstants.length], annotatedClass);
String[] names = ai.findEnumValues(config, annotatedClass,
enumConstants, new String[enumConstants.length]);
final String[][] allAliases = new String[names.length][];
ai.findEnumAliases(config, enumConstants, allAliases, annotatedClass);
ai.findEnumAliases(config, annotatedClass, enumConstants, allAliases);

// finally, build
HashMap<String, Enum<?>> map = new HashMap<String, Enum<?>>();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -146,8 +146,8 @@ public String[] findEnumValues(Class<?> enumType, Enum<?>[] enumValues, String[
}

@Override
public String[] findEnumValues(MapperConfig<?> config, Enum<?>[] enumValues, String[] names,
AnnotatedClass annotatedClass) {
public String[] findEnumValues(MapperConfig<?> config, AnnotatedClass annotatedClass,
Enum<?>[] enumValues, String[] names) {
// kinda sorta wrong, but for testing's sake...
for (int i = 0, len = enumValues.length; i < len; ++i) {
names[i] = enumValues[i].name().toLowerCase();
Expand Down

0 comments on commit b08f622

Please sign in to comment.