Skip to content

[Bug] Custom converters registered via registerConverter() are never used during write — silently falls back to the built-in converter, or throws "Converter not found" if none exists #1102

Description

@roysti10

Search before asking

  • I searched in the issues and found nothing similar.

Fesod version

2.0.2-incubating

JDK version

11

Operating system

Windows 11

Steps To Reproduce

public class AlwaysZeroIntegerConverter implements Converter<Integer> {
    public Class<?> supportJavaTypeKey() { return Integer.class; }
    public CellDataTypeEnum supportExcelTypeKey() { return CellDataTypeEnum.NUMBER; }

    public Integer convertToJavaData(...) { return 0; }   // deliberately wrong, so it's unmistakable
    public WriteCellData<?> convertToExcelData(WriteConverterContext<Integer> ctx) {
        return new WriteCellData<>(new BigDecimal(999));   // deliberately wrong, so it's unmistakable
    }
}

public class IntRow {
    @ExcelProperty("n")
    private Integer n;   // will be set to 42
}

// ...
IntRow row = new IntRow();
row.setN(42);

FesodSheet.write(file, IntRow.class)
    .registerConverter(new AlwaysZeroIntegerConverter())
    .sheet()
    .doWrite(List.of(row));

Current Behavior

It writes 42 into the xlsx file, instead of 999

Expected Behavior

it should write 999 into the xlsx file

Anything else?

RCA: Built in write converters are keyed by Java Type but these custom converters are keyed by both java type and excel cell type. At the write time only converts keyed by java type are searched causing the write path to completely ignore the custom converters

Fix would be to key it by java type only in the AbstractWriteHolder

Happy to share a PR for this!

Are you willing to submit a PR?

  • I'm willing to submit a PR!

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions