-
-
Notifications
You must be signed in to change notification settings - Fork 1.4k
Handle Enum
introspection of values and aliases via AnnotatedClass
instead of Class<?>
#3832
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 12 commits
0ff49d2
d9b70a9
b11db13
fbcc1c3
3ebe045
4cdef6c
bcd9025
ed21cf3
e33619e
39ff50d
51f923b
1f7bbc1
9478871
2a80825
b9a0677
05d77bb
ac04e46
caac7f5
b8447f7
89d80de
4440da0
e132e9d
244a871
baa9c8c
5143724
ad73809
a20d61d
d3a57ee
872dd10
8ae8ff4
e89a778
abbee55
d4d56e2
c07dd2f
47788f0
99cf1f7
0669e3c
1bd982a
833f6c4
dca4506
e3f7b1b
ac2af2b
aa589e5
50570b9
f91657c
c78a0e4
5d98b69
5a85d0b
3b89923
db48e04
6bbf646
f68e42b
24f3f45
1f5baf6
426fef5
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 |
---|---|---|
|
@@ -240,6 +240,44 @@ public String[] findEnumValues(Class<?> enumType, Enum<?>[] enumValues, String[] | |
return names; | ||
} | ||
|
||
@Override // since 2.15 | ||
public String[] findEnumValues(Class<?> enumType, Enum<?>[] enumValues, String[] names, AnnotatedClass annotatedClass) { | ||
HashMap<String, String> enumToPropertyMap = new HashMap<>(); | ||
|
||
for (AnnotatedField field : annotatedClass._fields) { | ||
JooHyukKim marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
JsonProperty property = field.getAnnotation(JsonProperty.class); | ||
JooHyukKim marked this conversation as resolved.
Show resolved
Hide resolved
|
||
if (property != null) { | ||
enumToPropertyMap.put(field.getName(), property.value()); | ||
|
||
} | ||
} | ||
|
||
HashMap<String,String> expl = null; | ||
for (Field f : enumType.getDeclaredFields()) { | ||
|
||
if (!f.isEnumConstant()) { | ||
continue; | ||
} | ||
|
||
String n = enumToPropertyMap.get(f.getName()); | ||
if (n == null || n.isEmpty()) { | ||
|
||
continue; | ||
} | ||
if (expl == null) { | ||
expl = new HashMap<String,String>(); | ||
} | ||
expl.put(f.getName(), n); | ||
} | ||
// and then stitch them together if and as necessary | ||
if (expl != null) { | ||
for (int i = 0, end = enumValues.length; i < end; ++i) { | ||
String defName = enumValues[i].name(); | ||
String explValue = expl.get(defName); | ||
if (explValue != null) { | ||
names[i] = explValue; | ||
} | ||
} | ||
} | ||
return names; | ||
} | ||
JooHyukKim marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
@Override // since 2.11 | ||
public void findEnumAliases(Class<?> enumType, Enum<?>[] enumValues, String[][] aliasList) | ||
{ | ||
|
@@ -264,6 +302,23 @@ public void findEnumAliases(Class<?> enumType, Enum<?>[] enumValues, String[][] | |
} | ||
} | ||
|
||
@Override // 2.15 | ||
public void findEnumAliases(Class<Enum<?>> enumType, Enum<?>[] enumValues, String[][] aliasList, AnnotatedClass annotatedClass) | ||
{ | ||
HashMap<String, String[]> enumToAliasMap = new HashMap<>(); | ||
for (AnnotatedField field : annotatedClass._fields) { | ||
JsonAlias alias = field.getAnnotation(JsonAlias.class); | ||
if (alias != null) { | ||
enumToAliasMap.putIfAbsent(field.getName(), alias.value()); | ||
} | ||
} | ||
|
||
for (int i = 0, end = enumValues.length; i < end; ++i) { | ||
Enum<?> enumValue = enumValues[i]; | ||
aliasList[i] = enumToAliasMap.getOrDefault(enumValue.name(), new String[]{}); | ||
} | ||
} | ||
|
||
JooHyukKim marked this conversation as resolved.
Show resolved
Hide resolved
|
||
/** | ||
* Finds the Enum value that should be considered the default value, if possible. | ||
* <p> | ||
|
Uh oh!
There was an error while loading. Please reload this page.