bengbengbalabalabeng commented on issue #889:
URL: https://github.com/apache/fesod/issues/889#issuecomment-4125954489

   Hi, @fyeeme
   
   I reproduced your minimal example locally (outside of a unit‑test 
environment) and confirmed that the `StackOverflowError` may not the actual 
root cause. The real issue is that Fesod fails to correctly resolve a matching 
`Converter` for the `ZonedDateTime` field.
   
   I validated the behavior using the following test code (essentially 
identical to your original repro):
   
   ```java
   @Slf4j
   class FesodNativeMetadataRegression {
   
       public static void main(String[] args) throws Throwable {
           String sheetName = "NativeMixedMetadata";
           ByteArrayOutputStream output = new ByteArrayOutputStream();
   
           FesodSheet.write(output, NativeMixedMetadataRow.class)
                   .registerConverter(new NativeZonedDateStringConverter())
                   .sheet(sheetName)
                   .doWrite(List.of(createRow()));
   
           ByteArrayInputStream input = new 
ByteArrayInputStream(output.toByteArray());
           Workbook workbook = WorkbookFactory.create(input);
           Sheet sheet = workbook.getSheet(sheetName);
           Row dataRow = sheet.getRow(1);
   
           Cell statusCell = dataRow.getCell(0);
           Validate.isTrue(Objects.equals("STATUS:ACTIVE", 
statusCell.getStringCellValue()), "status does not match");
   
           Cell amountCell = dataRow.getCell(1);
           Validate.isTrue(Objects.equals(1234.5, 
amountCell.getNumericCellValue()), "amount does not match");
   
           Cell createdAtCell = dataRow.getCell(2);
           Validate.isTrue(Objects.equals("2026-03-24 15:30:45", 
createdAtCell.getStringCellValue()), "createdAt does not match");
   
           log.info("done...");
       }
   }
   ```
   
   Error log:
   
   ```
   Exception in thread "main" 
org.apache.fesod.sheet.exception.ExcelWriteDataConvertException:
    Can not find 'Converter' support class ZonedDateTime.
   ```
   
   For the reason of this error, please refer to issue #648.
   
   ---
   
   **Solution (temporary)**
   
   Please try to modify the custom Converter, override the 
`supportExcelTypeKey` method and return null.
   
   ```java
   public static class NativeZonedDateStringConverter2 implements 
Converter<ZonedDateTime> {
       @Override
       public Class<?> supportJavaTypeKey() {
           return ZonedDateTime.class;
       }
   
       @Override
       public CellDataTypeEnum supportExcelTypeKey() {
           return null;
       }
   
       @Override
       public WriteCellData<?> convertToExcelData(
               ZonedDateTime value, ExcelContentProperty contentProperty, 
GlobalConfiguration globalConfiguration) {
           String format = contentProperty != null && 
contentProperty.getDateTimeFormatProperty() != null
                   ? contentProperty.getDateTimeFormatProperty().getFormat()
                   : "yyyy-MM-dd HH:mm:ss";
           return new 
WriteCellData<>(value.toLocalDateTime().format(java.time.format.DateTimeFormatter.ofPattern(format)));
       }
   }
   ```
   
   With this change applied, both the main method and the unit test pass 
successfully.
   
   **Unit Test**
   
   ```java
   @Test
   void nativePojoExport_shouldSuccess() throws Throwable {
       String sheetName = "NativeMixedMetadata";
   
       ByteArrayOutputStream output = new ByteArrayOutputStream();
   
       assertDoesNotThrow(() -> {
           FesodSheet.write(output, NativeMixedMetadataRow.class)
                   .registerConverter(new NativeZonedDateStringConverter2())
                   .sheet(sheetName)
                   .doWrite(List.of(createRow()));
       });
   
       ByteArrayInputStream input = new 
ByteArrayInputStream(output.toByteArray());
       Workbook workbook = WorkbookFactory.create(input);
       Sheet sheet = workbook.getSheet(sheetName);
       Row dataRow = sheet.getRow(1);
   
       Cell statusCell = dataRow.getCell(0);
       assertEquals("STATUS:ACTIVE", statusCell.getStringCellValue());
   
       Cell amountCell = dataRow.getCell(1);
       assertEquals(1234.5, amountCell.getNumericCellValue());
   
       Cell createdAtCell = dataRow.getCell(2);
       assertEquals("2026-03-24 15:30:45", createdAtCell.getStringCellValue());
   }
   ```


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to