Skip to content
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

Fix regression for JAXB annotations by implementing findEnumValues(MapperConfig, AnnotatedClass, Enum[], String[]) #212

Merged
merged 2 commits into from
Jul 4, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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;
}

Copy link
Member Author

@JooHyukKim JooHyukKim Jun 21, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

All same wrt to original method, except line 964 w/ @XmlEnumValue

/*
/**********************************************************************
/* 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;
}
Copy link
Member Author

@JooHyukKim JooHyukKim Jun 21, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@cowtowncoder Changes in JakartaXmlBindAnnotationIntrospector alone will fix the build failure. But if I understood correctly, this JaxbAnnotationIntrospector needs implementation here also...?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Correct, thanks. I think build fails on first module failing to pass tests so since "jakarta-xmlbind" is run before "jaxb" it'll be one breaking build.


/*
/**********************************************************
/* Deserialization: general annotations
Expand Down