diff --git a/jakarta-xmlbind/src/main/java/com/fasterxml/jackson/module/jakarta/xmlbind/JakartaXmlBindAnnotationIntrospector.java b/jakarta-xmlbind/src/main/java/com/fasterxml/jackson/module/jakarta/xmlbind/JakartaXmlBindAnnotationIntrospector.java index 347e4893..197564dc 100644 --- a/jakarta-xmlbind/src/main/java/com/fasterxml/jackson/module/jakarta/xmlbind/JakartaXmlBindAnnotationIntrospector.java +++ b/jakarta-xmlbind/src/main/java/com/fasterxml/jackson/module/jakarta/xmlbind/JakartaXmlBindAnnotationIntrospector.java @@ -951,6 +951,36 @@ public String[] findEnumValues(Class enumType, Enum[] enumValues, String[] return names; } + /** + * @see JacksonAnnotationIntrospector#findEnumValues(MapperConfig, AnnotatedClass, Enum[], String[]) + * @since 2.16 + */ + @Override + public String[] findEnumValues(MapperConfig config, AnnotatedClass annotatedClass, + Enum[] enumValues, String[] names) + { + Map enumToPropertyMap = new LinkedHashMap(); + for (AnnotatedField field : annotatedClass.fields()) { + XmlEnumValue property = field.getAnnotation(XmlEnumValue.class); + if (property != null) { + String propValue = property.value(); + if (propValue != null && !propValue.isEmpty()) { + enumToPropertyMap.put(field.getName(), propValue); + } + } + } + + // and then stitch them together if and as necessary + for (int i = 0, end = enumValues.length; i < end; ++i) { + String defName = enumValues[i].name(); + String explValue = enumToPropertyMap.get(defName); + if (explValue != null) { + names[i] = explValue; + } + } + return names; + } + /* /********************************************************************** /* Deserialization: general annotations diff --git a/jaxb/src/main/java/com/fasterxml/jackson/module/jaxb/JaxbAnnotationIntrospector.java b/jaxb/src/main/java/com/fasterxml/jackson/module/jaxb/JaxbAnnotationIntrospector.java index 5744d900..9da2cfa2 100644 --- a/jaxb/src/main/java/com/fasterxml/jackson/module/jaxb/JaxbAnnotationIntrospector.java +++ b/jaxb/src/main/java/com/fasterxml/jackson/module/jaxb/JaxbAnnotationIntrospector.java @@ -969,6 +969,36 @@ public String[] findEnumValues(Class enumType, Enum[] enumValues, String[] return names; } + /** + * @see JacksonAnnotationIntrospector#findEnumValues(MapperConfig, AnnotatedClass, Enum[], String[]) + * @since 2.16 + */ + @Override + public String[] findEnumValues(MapperConfig config, AnnotatedClass annotatedClass, + Enum[] enumValues, String[] names) + { + Map enumToPropertyMap = new LinkedHashMap(); + for (AnnotatedField field : annotatedClass.fields()) { + XmlEnumValue property = field.getAnnotation(XmlEnumValue.class); + if (property != null) { + String propValue = property.value(); + if (propValue != null && !propValue.isEmpty()) { + enumToPropertyMap.put(field.getName(), propValue); + } + } + } + + // and then stitch them together if and as necessary + for (int i = 0, end = enumValues.length; i < end; ++i) { + String defName = enumValues[i].name(); + String explValue = enumToPropertyMap.get(defName); + if (explValue != null) { + names[i] = explValue; + } + } + return names; + } + /* /********************************************************** /* Deserialization: general annotations