Skip to content

Commit

Permalink
Merge pull request #212 from JooHyukKim/211-Regression-for-enum
Browse files Browse the repository at this point in the history
Fix regression for JAXB annotations by implementing `findEnumValues(MapperConfig, AnnotatedClass, Enum[], String[])`
  • Loading branch information
cowtowncoder committed Jul 4, 2023
2 parents 9dcc41f + ccd0634 commit dde5413
Show file tree
Hide file tree
Showing 2 changed files with 60 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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<String, String> enumToPropertyMap = new LinkedHashMap<String, String>();
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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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<String, String> enumToPropertyMap = new LinkedHashMap<String, String>();
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
Expand Down

0 comments on commit dde5413

Please sign in to comment.