Skip to content

fix: honor wildcard-key custom converters when writing CSV (#1045) (#1056) - #1069

Merged
delei merged 8 commits into
apache:mainfrom
Mikkey-f:feat/1045-csv-wildcard-converter
Nov 22, 2026
Merged

delei merged 8 commits into
apache:mainfrom
Mikkey-f:feat/1045-csv-wildcard-converter

Conversation

@Mikkey-f

@Mikkey-f Mikkey-f commented Sep 7, 2026 •

Copy link
Copy Markdown
Contributor

What changed

Custom converters registered with supportExcelTypeKey() == null (the wildcard key (JavaType, null)) are now resolved as a fallback when the write path forces a concrete target cell data type. A single registerConverter(...) call works for both xlsx and CSV writes, and the last wildcard registration wins consistently across formats.

Why

AbstractExcelWriteExecutor#doConvert resolves converters with the key (JavaType, targetCellDataType). The xlsx write path leaves the target type null, so a wildcard registration (JavaType, null) is found. The CSV write path forces the target type to STRING, so the same registration misses and the built-in string converter silently takes over: no warning is logged and the CSV output silently diverges from the xlsx output of the same code. See #1045 and #1056 (same root cause as EasyExcel#3054).

A registration-time copy of the wildcard converter into (JavaType, STRING) fixes the single-converter case, but cannot express both "explicit registration always wins" and "last wildcard registration wins": two wildcard registrations leave CSV on the first one while xlsx uses the last one.

How

AbstractExcelWriteExecutor#resolveConverter resolves in one place:

  1. A converter explicitly registered for the exact (JavaType, targetCellDataType) key.
  2. Otherwise, a custom converter registered under the wildcard key (JavaType, null).
  3. Otherwise, the exact key (possibly a built-in default).

Built-in instances are recognised by identity against DefaultConverterLoader.loadDefaultWriteConverter(). Registration (AbstractWriteHolder) is back to storing only the declared key, so each Java type has exactly one wildcard converter and the last registration wins.

ExcelWriteFillExecutor#doFill now also handles DATE and RICH_TEXT_STRING results when composing multi-variable template text, so a wildcard converter that returns a date or rich-text cell no longer drops its value.

Impact

  • Without custom converters: unaffected.
  • Explicit-key registrations: unaffected, and they still beat wildcard registrations regardless of order.
  • Wildcard (null-key) registrations: CSV now applies the custom converter instead of silently falling back to the built-in string converter, and multiple wildcard registrations match xlsx (last one wins). The template-fill composition path shares the resolution and additionally stringifies DATE/RICH_TEXT results.
  • Field-level converters (@ExcelProperty(converter = ...)) bypass the registry entirely and are unaffected.

Documentation

The null semantics of Converter#supportExcelTypeKey() are documented on the method (javadoc) and on the website converter page (EN and zh-cn).

Tests

WildcardConverterWriteTest (10 tests):

  • xlsx wildcard converter applies
  • CSV wildcard converter applies — red before the fix: output was true/false instead of the custom values
  • explicit STRING-key registration wins over a wildcard, in both registration orders
  • CSV without custom converters unchanged (still true/false)
  • two wildcard registrations: the last one wins for both xlsx and CSV
  • fill composition with a DATE result and a STRING result (2024-01-02 03:04:05 / NO)
  • fill composition with a RICH_TEXT_STRING result
  • registration stays on the wildcard key; the built-in STRING default is not displaced

Red/green verified: the failing cases were reproduced against the pre-fix code, then turned green by the fix.

Full suite: 1,885 tests green (1 skipped on Windows), spotless and javadoc pass.

Fixes #1045
Fixes #1056

@Mikkey-f
Mikkey-f force-pushed the feat/1045-csv-wildcard-converter branch from 2b5190f to 68b4bb3 Compare September 7, 2026 06:20
@psxjoy
psxjoy requested a lite review from Copilot September 7, 2026 06:21

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

🟡 Changes recommended

The current wildcard registration logic can overwrite explicitly-registered (JavaType, STRING) converters depending on registration order, and one new test reads the “workbook” converter map via currentWriteHolder() which may not actually be the workbook holder after a write.

Once you've addressed the issues Copilot identified, you can request another Copilot review.

Pull request overview

This PR fixes a long-standing inconsistency where custom write converters registered with a wildcard excel-type key (supportExcelTypeKey() == null) were applied for XLSX writes but silently ignored for CSV writes (which force converter lookup under (JavaType, STRING)). The approach is to duplicate wildcard registrations under the CSV lookup key without changing the converter resolution logic.

Changes:

  • Register wildcard-key custom converters under both (JavaType, null) and (JavaType, STRING) during write-holder initialization.
  • Add a new regression test suite covering wildcard vs explicit converter behavior across XLSX/CSV and across workbook/sheet holder registration paths.
  • Document the supportExcelTypeKey() == null wildcard semantics in both EN and zh-cn docs and in the Converter javadoc.
File summaries
File Description
fesod-sheet/src/main/java/org/apache/fesod/sheet/write/metadata/holder/AbstractWriteHolder.java Adds helper-based converter registration and duplicates wildcard registrations for CSV compatibility.
fesod-sheet/src/main/java/org/apache/fesod/sheet/converters/Converter.java Expands javadoc to document wildcard semantics and CSV behavior.
fesod-sheet/src/test/java/org/apache/fesod/sheet/converter/WildcardConverterWriteTest.java Adds regression tests for wildcard converter application and registration in holder maps.
website/docs/sheet/write/converter.md Documents wildcard-key behavior (EN).
website/i18n/zh-cn/docusaurus-plugin-content-docs/current/sheet/write/converter.md Documents wildcard-key behavior (zh-cn).
Review details
  • Files reviewed: 5/5 changed files
  • Comments generated: 2
  • Review effort level: Lite

💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

Comment on lines +299 to +310
private void putCustomConverter(Converter<?> converter) {
getConverterMap()
.put(
ConverterKeyBuild.buildKey(converter.supportJavaTypeKey(), converter.supportExcelTypeKey()),
converter);
if (converter.supportExcelTypeKey() == null) {
getConverterMap()
.put(
ConverterKeyBuild.buildKey(converter.supportJavaTypeKey(), CellDataTypeEnum.STRING),
converter);
}
}

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Addressed: the (JavaType, STRING) registration now only replaces the occupant while it is still the built-in default converter (identity-checked against DefaultConverterLoader.loadDefaultWriteConverter()), so an explicitly registered converter is never displaced regardless of registration order; supportExcelTypeKey() is cached in a local. Regression test csvExplicitStringKeyRegisteredBeforeWildcardStillWins covers the order you described.

Comment on lines +131 to +135
Map<ConverterKeyBuild.ConverterKey, Converter<?>> workbookMap =
excelWriter.writeContext().currentWriteHolder().converterMap();
Map<ConverterKeyBuild.ConverterKey, Converter<?>> sheetMap =
excelWriter.writeContext().writeSheetHolder().converterMap();
excelWriter.finish();

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Addressed: workbookMap now reads writeWorkbookHolder().converterMap() — after write() the current holder is the sheet holder, so the two maps were aliased. The writer is now closed via try-with-resources.

@BigDataDZ BigDataDZ left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Reviewed as the author of the read-side counterpart (#1086) - this is the right shape for the write side, and I can confirm the registration semantics here are consistent with what the read-side fix ended up doing.

What stands out as particularly well done:

  • The putCustomConverter guard is the part I was worried about before reading it: expanding a wildcard (JavaType, null) registration into (JavaType, STRING) would naively displace an explicitly registered (JavaType, STRING) converter depending on registration order. Taking over the slot only when the occupant is absent or identity-equal to the built-in default (== DefaultConverterLoader.loadDefaultWriteConverter().get(stringKey)) makes the outcome order-independent, and the shallow parent copy keeps the identity check valid for inherited holders too.
  • The wildcard's (JavaType, STRING) slot is also found by the xlsx path when a field's target cell type is explicitly STRING, so behavior is consistent for both formats regardless of which key the executor builds - a bonus beyond the CSV fix itself.
  • The Converter javadoc + bilingual docs make the null contract explicit, which was my main gripe as a user hitting this in #1056's repro.

Two non-blocking thoughts:

  1. Once this and #1086 both land, the "Converter Resolution Priority" docs section could use a short paragraph describing the read/write asymmetry: read resolves by the concrete cell type key (xlsx/xls included), write resolves wildcard on xlsx/xls but forced STRING on CSV. Happy to draft that paragraph when either merges, so the two sides are documented together rather than in two places.
  2. The class-level javadoc on XlsFormatTrackingListener-style details aside, WildcardConverterWriteTest covering explicit-priority preservation (explicit (JavaType, STRING) registered before AND after a wildcard registration) would lock the order-independence claim - if it is already in there, even better.

Nice work - this unblocks the converter story for CSV writes that #1045/#1056 have been waiting on.

@Mikkey-f

Copy link
Copy Markdown
Contributor Author

Thanks for the careful read — and for checking the guard against the shallow parent copy specifically. Order-independence was the exact thing Copilot's earlier review flagged, so it's good to have it confirmed from the read-side perspective as well.

On your two points:

  1. Docs paragraph — agreed it should read as one story rather than two, and I'd rather you draft it: you have the read-side resolution order freshest, and it will come out more naturally from that side. Happy to review or co-write from the write side whenever you want to start.

  2. Registration-order test — added csvExplicitStringKeyRegisteredAfterWildcardStillWins (explicit (JavaType, STRING) registered after the wildcard; both rows asserted), so the invariant is now locked in both orders alongside the existing csvExplicitStringKeyRegisteredBeforeWildcardStillWins.

Also merged current main into the branch, so it's no longer behind.

@BigDataDZ

Copy link
Copy Markdown
Contributor

Great - here is a draft for the shared paragraph, written to drop into the "Converter Resolution Priority" section of both docs pages (read and write). Wording follows what our two implementations actually do:


Converter resolution across read and write

Registered converters are looked up by the key (JavaType, CellDataType), but the two directions build that key differently, and both give priority to explicit registrations over wildcard ones.

Write. The target cell type is null for xlsx/xls (the converter decides the cell type it produces) and forced to STRING for CSV. A converter registered with supportExcelTypeKey() == null (the wildcard key (JavaType, null)) therefore wins on xlsx/xls writes directly, and is additionally registered under (JavaType, STRING) so CSV honors it too. That extra registration only takes over the STRING slot when it is still held by the built-in default, so an explicitly registered converter is never displaced, regardless of registration order.

Read. Cells carry a concrete type from the file, so every format resolves (JavaType, cellData.getType()) - e.g. (Boolean, STRING) for a text cell. A wildcard read registration is expanded under every concrete cell-type key (overwriting built-in defaults, skipping EMPTY), while keys already held by an explicitly registered converter are left untouched - again, explicit wins.

In short: one wildcard registration covers every format and every cell type, an explicit registration always beats the wildcard, and user registrations always beat built-ins.


If the wording works for you, I will add it to the read-side converter docs in #1086 (both EN and zh-CN, mirroring what you did for the write page); if #1069 merges first, feel free to fold the same text into the write page so neither ships a half story. Edits welcome, it is meant as a starting point.

@Mikkey-f

Copy link
Copy Markdown
Contributor Author

Thanks — this reads well, and I went through it against both implementations line by line. The write-side description matches #1069 exactly (including why the extra (JavaType, STRING) registration is order-independent: it only takes the slot while the built-in default still holds it), and the read-side description matches the expansion in #1086 (explicit keys claimed first, EMPTY skipped, built-ins overridden).

One addition worth considering: with the header-path fix in #1098, the header row resolves against the built-in converters only, so "user registrations always beat built-ins" could be read as universal. A closing sentence would keep the summary honest, e.g. "The header row is resolved against the built-in converters only: registered converters apply to data cells, never to the header text used for @ExcelProperty name matching." It only becomes accurate once #1098 lands, so adding it after that merges may be best — your call.

On placement: agreed on one story rather than two. Go ahead and add it to the read page in #1086. I'll fold the same paragraph (plus that header note once #1098 is in) into the write page after either PR lands, so no page documents behaviour that has not shipped yet — but if you'd rather cover both pages in #1086, that works for me too.

BigDataDZ added a commit to BigDataDZ/fesod that referenced this pull request Oct 11, 2026
Add the shared "Converter resolution across read and write" paragraph to the
read-side converter docs (EN and zh-CN), as agreed in apache#1069: how the
(JavaType, CellDataType) lookup key is built per direction, why explicit
registrations beat wildcard ones, and how CSV's forced STRING write type
interacts with the wildcard registration.

The header-row note is intentionally left out until apache#1098 lands.

Generated-by: ZCode
@BigDataDZ

Copy link
Copy Markdown
Contributor

Done — added the shared paragraph to the read page in #1086 (EN and zh-CN), under a "Converter Resolution Priority" section so it drops into the write page's same-named section unchanged. Commit: e717b5d.

On the header note: agreed it should wait until #1098 lands, so I left it out — the read page now only describes shipped behaviour. Over to you for the write-page fold-in once either PR merges.

@delei

delei commented Nov 20, 2026 •

Copy link
Copy Markdown
Member

Hi, @Mikkey-f
Thank you for your contribution—this is a valuable PR.

Scenario

After thoroughly reviewing this PR and the corresponding issue, I tried adding a few unit test cases. I found that there's an issue in the following case:

@Test
void lastWildcardRegistrationWinsInBothFormats() throws Exception {
    List<List<Boolean>> rows = Collections.singletonList(Collections.singletonList(Boolean.TRUE));

    File csv = new File(tempDir, "two-wildcards.csv");
    FesodSheet.write(csv)
            .excelType(ExcelTypeEnum.CSV)
            .charset(StandardCharsets.UTF_8)
            .registerConverter(new TaggedConverter("A"))
            .registerConverter(new TaggedConverter("B"))
            .sheet()
            .doWrite(rows);
    String csvContent = new String(Files.readAllBytes(csv.toPath()), StandardCharsets.UTF_8);

    File xlsx = new File(tempDir, "two-wildcards.xlsx");
    FesodSheet.write(xlsx)
            .excelType(ExcelTypeEnum.XLSX)
            .registerConverter(new TaggedConverter("A"))
            .registerConverter(new TaggedConverter("B"))
            .sheet()
            .doWrite(rows);
    String xlsxValue;
    try (Workbook workbook = WorkbookFactory.create(xlsx)) {
        xlsxValue = workbook.getSheetAt(0).getRow(0).getCell(0).getStringCellValue();
    }

    Assertions.assertEquals("result-B", xlsxValue);
    Assertions.assertTrue(
            csvContent.contains("result-B"),
            "CSV must match xlsx of the same code, but was: " + csvContent);
}

public static class TaggedConverter implements Converter<Boolean> {
    private final String tag;

    public TaggedConverter(String tag) {
        this.tag = tag;
    }

    @Override
    public Class<?> supportJavaTypeKey() {
        return Boolean.class;
    }

    @Override
    public CellDataTypeEnum supportExcelTypeKey() {
        return null;
    }

    @Override
    public WriteCellData<?> convertToExcelData(
            Boolean value, ExcelContentProperty contentProperty, GlobalConfiguration globalConfiguration) {
        return new WriteCellData<>("result-" + tag);
    }
}

Result

org.opentest4j.AssertionFailedError: CSV must match xlsx of the same code, but was: result-A
 ==> 
Expected :true
Actual   :false

Tested on current PR code: CSV = result-A, XLSX = result-B; assertion failed!

The new proposal

  1. No change needed in AbstractWriteHolder;
private void putCustomConverter(Converter<?> converter) {
    Class<?> javaTypeKey = converter.supportJavaTypeKey();
    CellDataTypeEnum excelTypeKey = converter.supportExcelTypeKey();
    getConverterMap().put(ConverterKeyBuild.buildKey(javaTypeKey, excelTypeKey), converter);
}
  1. Improve AbstractExcelWriteExecutor#doConvert method - CSV defaulting the target cell type to STRING already lives there, so the semantics stay in one place. Add a new resolveConverter helper that spells out the order:
private Converter<?> resolveConverter(Class<?> fieldClass, CellDataTypeEnum targetCellDataType)  {
    Map<ConverterKeyBuild.ConverterKey, Converter<?>> converterMap =
            writeContext.currentWriteHolder().converterMap();
    ConverterKeyBuild.ConverterKey exactKey = ConverterKeyBuild.buildKey(fieldClass, targetCellDataType);
    Converter<?> exactConverter = converterMap.get(exactKey);
    if (targetCellDataType == null) {
        // Regular xlsx cells already look up the wildcard key itself, nothing to fall back to.
        return exactConverter;
    }
    Map<ConverterKeyBuild.ConverterKey, Converter<?>> defaultConverterMap =
            DefaultConverterLoader.loadDefaultWriteConverter();
    if (exactConverter != null && exactConverter != defaultConverterMap.get(exactKey)) {
        // An explicitly registered converter always wins over a wildcard one.
        return exactConverter;
    }
    ConverterKeyBuild.ConverterKey wildcardKey = ConverterKeyBuild.buildKey(fieldClass, null);
    Converter<?> wildcardConverter = converterMap.get(wildcardKey);
    if (wildcardConverter != null && wildcardConverter != defaultConverterMap.get(wildcardKey)) {
        // Only a custom (non built-in) wildcard converter may take over a forced cell data type.
        return wildcardConverter;
    }
    // No custom wildcard converter: keep the exact (possibly default) converter.
    return exactConverter;
}

with doConvert becoming:

private WriteCellData<?> doConvert(CellWriteHandlerContext cellWriteHandlerContext) {
    ExcelContentProperty excelContentProperty = cellWriteHandlerContext.getExcelContentProperty();

    Converter<?> converter = null;
    if (excelContentProperty != null) {
        converter = excelContentProperty.getConverter();
    }
    if (converter == null) {
        // csv is converted to string by default
        if (writeContext.writeWorkbookHolder().getExcelType() == ExcelTypeEnum.CSV) {
            cellWriteHandlerContext.setTargetCellDataType(CellDataTypeEnum.STRING);
        }
        // No field-level converter configured: resolve one from the field class and target cell data type.
        converter = resolveConverter(
                cellWriteHandlerContext.getOriginalFieldClass(),
                cellWriteHandlerContext.getTargetCellDataType());
    }
    
    // ... existing code

}

This proposal may not cover all scenarios. Further discussion and refinement can be carried out.


BTW, this is not an objection, I'm glad to work with the contributor to get this PR merged.

@delei

delei commented Nov 20, 2026

Copy link
Copy Markdown
Member

For the Fill mode, a new issue was also discovered, but this seems to be another scenario that requires improvement. I also suggest that we work together to fix it.

Scenario

@Test
void xlsxFillCompositionKeepsValueForWildcardConverter() throws Exception {
    File template = new File(tempDir, "compose-template.xlsx");
    FesodSheet.write(template)
            .sheet()
            .doWrite(Collections.singletonList(Collections.singletonList("{a} / {b}")));

    File file = new File(tempDir, "compose-filled.xlsx");
    Map<String, Object> data = new HashMap<>();
    data.put("a", LocalDateTime.of(2024, 1, 2, 3, 4, 5));
    data.put("b", Boolean.FALSE);

    FesodSheet.write(file)
            .withTemplate(template)
            .registerConverter(new LocalDateTimeWildcardConverter())
            .registerConverter(new BooleanYesNoConverter())
            .sheet()
            .doFill(data);

    try (Workbook workbook = WorkbookFactory.create(file)) {
        Assertions.assertEquals(
                "2024-01-02 03:04:05 / NO",
                workbook.getSheetAt(0).getRow(0).getCell(0).getStringCellValue());
    }
}

public static class LocalDateTimeWildcardConverter implements Converter<LocalDateTime> {
    @Override
    public Class<?> supportJavaTypeKey() {
        return LocalDateTime.class;
    }

    @Override
    public CellDataTypeEnum supportExcelTypeKey() {
        return null;
    }

    @Override
    public WriteCellData<?> convertToExcelData(
            LocalDateTime value,
            ExcelContentProperty contentProperty,
            GlobalConfiguration globalConfiguration) {
        // Return types not supported in the Fill mode
        return new WriteCellData<>(value);
    }
}

Result

org.opentest4j.AssertionFailedError: 
Expected :2024-01-02 03:04:05 / NO
Actual   :2024-01-02 03:04:05 / false

Proposal

Improve the semantics of the ExcelWriteFillExecutor#doFill method's switch statement to support more types

if (type != null) {
    switch (type) {
        case STRING:
            cellValueBuild.append(cellData.getStringValue());
            break;
        case BOOLEAN:
            cellValueBuild.append(cellData.getBooleanValue());
            break;
        case NUMBER:
            cellValueBuild.append(cellData.getNumberValue());
            break;
        case DATE:
            cellValueBuild.append(DateUtils.format(
                    cellData.getDateValue(),
                    Optional.ofNullable(cellData.getWriteCellStyle())
                            .map(WriteCellStyle::getDataFormatData)
                            .map(DataFormatData::getFormat)
                            .orElse(null),
                    Locale.getDefault()));
            break;
        case RICH_TEXT_STRING:
            cellValueBuild.append(StyleUtil.buildRichTextString(
                    writeContext.writeWorkbookHolder(), cellData.getRichTextStringDataValue()));
            break;
        default:
            break;
    }
}

@bengbengbalabalabeng

Copy link
Copy Markdown
Contributor

Hi @delei, @Mikkey-f,

Given that Issue #1104 and PR #1128 are currently adjusting the related Converter architecture, it is recommended to first review the content involved in the current changes in light of these two discussions.

@delei

delei commented Nov 21, 2026

Copy link
Copy Markdown
Member

Given that Issue #1104 and PR #1128 are currently adjusting the related Converter architecture, it is recommended to first review the content involved in the current changes in light of these two discussions.

Thank you for mentioning it. :)
I have noticed these related PRs ( #1069 , #1086 , #1128 ). I am willing to offer support to the current PR contributors from the perspective of a single PR. This depends on my personal perspective.

I didn't mean any offense, I can communicate and collaborate with these PRs in sequence, trying to avoid conflicts as much as possible. However, this might take some time.

Another option is that if these different contributors can reach a consensus in #1104 or ultimately adopt the proposal in #1104, that would also be a way, but it is not the only one.

@bengbengbalabalabeng

Copy link
Copy Markdown
Contributor

Thank you for mentioning it. :) I have noticed these related PRs ( #1069 , #1086 , #1128 ). I am willing to offer support to the current PR contributors from the perspective of a single PR. This depends on my personal perspective.

I didn't mean any offense, I can communicate and collaborate with these PRs in sequence, trying to avoid conflicts as much as possible. However, this might take some time.

Another option is that if these different contributors can reach a consensus in #1104 or ultimately adopt the proposal in #1104, that would also be a way, but it is not the only one.

Thanks for the clarification.

My concern is not whether the current implementation is feasible. I only mentioned it because there is some overlap with the topics being discussed in #1104. The intention was simply to highlight the related discussion, not to block or delay the progress of this PR.

@delei

delei commented Nov 21, 2026

Copy link
Copy Markdown
Member

Thanks for the clarification.

My concern is not whether the current implementation is feasible. I only mentioned it because there is some overlap with the topics being discussed in #1104. The intention was simply to highlight the related discussion, not to block or delay the progress of this PR.

Hi, @bengbengbalabalabeng
It's okay. We can first focus on the changes made in the current PR and work together to attempt to merge this PR. :)

Wildcard fallback now happens when the converter is resolved instead of when it is registered:

- AbstractWriteHolder registers only the declared key, so the last wildcard registration wins for both xlsx and CSV.
- AbstractExcelWriteExecutor#resolveConverter prefers an explicit exact-key converter, then a custom wildcard converter, then the exact key (possibly a built-in default).
- ExcelWriteFillExecutor stringifies DATE and RICH_TEXT_STRING results when composing multi-variable text.

Tests cover two wildcard registrations, fill composition with DATE and rich text results, and that the registration stays on the wildcard key.
@Mikkey-f

Copy link
Copy Markdown
Contributor Author

Thanks @delei, this is a very useful review — I reproduced both scenarios on the branch and they point at two real gaps.

Why the CSV/xlsx mismatch happens. The registration-time fix copied a wildcard converter into (JavaType, STRING) only while that key still held a built-in default. With A then B: A owns both keys, then B overwrites (JavaType, null) but the guard refuses to copy B into (JavaType, STRING) because the occupant is A (no longer a built-in default). xlsx reads B, CSV reads A. One key cannot express both "explicit registration always wins" and "last wildcard registration wins" — so moving the decision to lookup time is the right call.

Applied your direction in 3196619:

  • AbstractWriteHolder#putCustomConverter is back to registering only the declared key, so there is a single wildcard converter per Java type and the last registration wins.
  • AbstractExcelWriteExecutor#resolveConverter resolves in the order you described: explicit exact key → custom wildcard key → exact key (possibly a built-in default). Built-in instances are recognised by identity against DefaultConverterLoader.loadDefaultWriteConverter().
  • ExcelWriteFillExecutor#doFill now handles DATE and RICH_TEXT_STRING results when composing multi-variable text.

Two small deviations from your snippets: DATE formatting reads the locale from writeContext.writeWorkbookHolder().globalConfiguration() (currently the JVM default, but it keeps the write configuration as the single source), and the rich-text branch appends RichTextStringData#getTextString() directly — building a POI RichTextString only to read the text back yields the same string.

Both of your scenarios are now regression tests (lastWildcardRegistrationWinsInBothFormats, fillCompositionStringifiesWildcardConverterResults), plus a rich-text composition case and a test pinning the registration to the wildcard key only. WildcardConverterWriteTest 10/10, full fesod-common (60) + fesod-shaded + fesod-sheet (1,885, 1 skipped as on main) green, spotless and javadoc clean.

On the architecture note: @bengbengbalabalabeng, thanks for flagging it. This change stays within the current Map-based registry and removes the registration-time special case, so it should port to CellDataConverterRegistry cleanly once #1128 lands. I'm following #1104/#1128 and glad to support that direction — happy to adapt this fallback afterwards, and to help test or review the registry work where useful. (My #1212 is already based on #1128 and waiting for it.)

delei
delei previously approved these changes Nov 21, 2026

@delei delei left a comment •

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

LGTM.

From the current PR's perspective, I believe it has achieved its goals and can be merged. The other related PRs can be regarded as further improvement measures.

I will wait for at least 24 hours before merging. If other members of the community are interested, PTAL.

@Mikkey-f

Copy link
Copy Markdown
Contributor Author

Thanks @delei — bengbeng's three review nits are applied in 246051d (test tag, ArrayList import, xlsx/xls wording), and CI is 16/16 green. The push dismissed the previous approval as stale; could you take another look and re-approve when you have a moment?

@bengbengbalabalabeng bengbengbalabalabeng left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

LGTM.

@delei
delei merged commit 67d0a23 into apache:main Nov 22, 2026
16 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[bug]Custom converters with supportExcelTypeKey() == null are silently ignored when writing CSV [Bug] Reuse one custom Converter in CSV and XLSX

5 participants