Search before asking
Fesod version
2.1.0-incubating (main branch, commit 4e3f3aa)
JDK version
Temurin 1.8.0_472
Operating system
Windows 10 (amd64)
Steps To Reproduce
Field names that start with a lower case letter followed by an upper case letter, for example xRealIp or pName, are common in generated DTOs (a X_REAL_IP column converted to camel case).
Data class:
public class CamelCaseFieldData {
@ExcelProperty("name")
private String name;
@ExcelProperty("xRealIp")
private String xRealIp;
@ExcelProperty("pName")
private String pName;
}
Test code:
File file = new File("camel.xlsx");
FesodSheet.write(file, CamelCaseFieldData.class)
.includeColumnFieldNames(Arrays.asList("name", "xRealIp", "pName"))
.sheet()
.doWrite(data());
List<Map<Integer, String>> dataMap = FesodSheet.read(file).sheet().doReadSync();
// only one column is written, the others are silently dropped
A test method with this content is added by the PR that fixes it: it fails on the current main branch and passes with the fix.
Current Behavior
includeColumnFieldNames(Arrays.asList("name", "xRealIp", "pName")) writes 1 column instead of 3, the xRealIp and pName columns are dropped from the file. excludeColumnFieldNames(Arrays.asList("xRealIp")) keeps the xRealIp column.
Cause: ClassUtils.doDeclaredFields filters with writeHolder.ignore(field.getFieldName(), ...), and FieldWrapper getFieldName is the name kept by the cglib bean map of the field (see FieldUtils resolveCglibFieldName), which is XRealIp for the field xRealIp. AbstractWriteHolder ignore compares that name with the field names configured by the user, so the comparison only works when the cglib name equals the Java field name, which is the case for names like column1 or name, but not for names like xRealIp or pName.
ClassUtils.resortField has the same problem: it looks the order of a column up by field.getFieldName() and assigns a position to every configured name, so an unknown name leaves a hole and shifts the following columns when orderByIncludeColumn(true) is used.
Expected Behavior
includeColumnFieldNames(Arrays.asList("name", "xRealIp", "pName")) writes all three columns, excludeColumnFieldNames(Arrays.asList("xRealIp")) writes name and pName only.
Filtering by field name must use the Java field name, which is the name the user configures and the name used when reading the file back, and an unknown name in the include list must not hold a column position.
Anything else?
Related EasyExcel issue, the same code exists there: alibaba/easyexcel#4110
I have a fix ready in a fork, it also adds unit tests: https://github.com/CodeMan-cmd/fesod/tree/fix-include-exclude-camel-case-field-name (PR follows).
Are you willing to submit a PR?
Search before asking
Fesod version
2.1.0-incubating (main branch, commit 4e3f3aa)
JDK version
Temurin 1.8.0_472
Operating system
Windows 10 (amd64)
Steps To Reproduce
Field names that start with a lower case letter followed by an upper case letter, for example
xRealIporpName, are common in generated DTOs (aX_REAL_IPcolumn converted to camel case).Data class:
Test code:
A test method with this content is added by the PR that fixes it: it fails on the current main branch and passes with the fix.
Current Behavior
includeColumnFieldNames(Arrays.asList("name", "xRealIp", "pName"))writes 1 column instead of 3, the xRealIp and pName columns are dropped from the file.excludeColumnFieldNames(Arrays.asList("xRealIp"))keeps the xRealIp column.Cause:
ClassUtils.doDeclaredFieldsfilters withwriteHolder.ignore(field.getFieldName(), ...), andFieldWrappergetFieldName is the name kept by the cglib bean map of the field (seeFieldUtilsresolveCglibFieldName), which isXRealIpfor the fieldxRealIp.AbstractWriteHolderignore compares that name with the field names configured by the user, so the comparison only works when the cglib name equals the Java field name, which is the case for names likecolumn1orname, but not for names likexRealIporpName.ClassUtils.resortFieldhas the same problem: it looks the order of a column up byfield.getFieldName()and assigns a position to every configured name, so an unknown name leaves a hole and shifts the following columns whenorderByIncludeColumn(true)is used.Expected Behavior
includeColumnFieldNames(Arrays.asList("name", "xRealIp", "pName"))writes all three columns,excludeColumnFieldNames(Arrays.asList("xRealIp"))writesnameandpNameonly.Filtering by field name must use the Java field name, which is the name the user configures and the name used when reading the file back, and an unknown name in the include list must not hold a column position.
Anything else?
Related EasyExcel issue, the same code exists there: alibaba/easyexcel#4110
I have a fix ready in a fork, it also adds unit tests: https://github.com/CodeMan-cmd/fesod/tree/fix-include-exclude-camel-case-field-name (PR follows).
Are you willing to submit a PR?