Migrating from 1.0.0
Version 1.1.0 contains two changes that break the compilation of some applications, and requires recompiling every sheet class. This section lists each case, the error it produces and the fix. Applications that do not use the attributes and types below only need to update the version.
| Change | Affects | Error | Section |
|---|---|---|---|
freezeHeader, autoFilter and autoSizeColumns are Toggle |
sheet classes that set one of them | compilation error | 2.2 |
| Annotation values are read with the new types | every sheet class compiled against 1.0.0, also inside other jars | AnnotationTypeMismatchException at run time |
2.3 |
CellValue has a seventh form, CellValue.Link |
code with an exhaustive switch on CellValue |
compilation error | 2.4 |
| More types have a built-in converter | nothing breaks | none | 2.5 |
Update the version
Section titled “Update the version”<dependency> <groupId>cloud.baldilorenzo.sheetsmith</groupId> <artifactId>sheetsmith-spring-boot-starter</artifactId> <version>1.1.0</version></dependency>The same applies to sheetsmith-core in applications without Spring Boot.
Layout options of @ExcelSheet
Section titled “Layout options of @ExcelSheet”freezeHeader, autoFilter and autoSizeColumns change type from boolean to Toggle, so that they can be left unset on a sheet class and taken from its template. A sheet class that sets one of them no longer compiles:
incompatible types: boolean cannot be converted to cloud.baldilorenzo.sheetsmith.style.ToggleFix. Write Toggle.TRUE instead of true and Toggle.FALSE instead of false, and import cloud.baldilorenzo.sheetsmith.style.Toggle.
@ExcelSheet(title = "Orders", freezeHeader = false, autoFilter = true)
// 1.1.0@ExcelSheet(title = "Orders", freezeHeader = Toggle.FALSE, autoFilter = Toggle.TRUE)The defaults have not changed: when neither the sheet class nor its template sets them, the header is frozen, no auto-filter is added and columns are sized automatically. freezeHeader = true and autoSizeColumns = true repeat the default and can simply be removed.
Recompile every sheet class
Section titled “Recompile every sheet class”The values of annotations are stored in the compiled classes. A sheet class compiled against 1.0.0 that sets one of the three layout options still holds a boolean value, which 1.1.0 reads as a Toggle. This happens when the library is updated and the classes are not compiled again, for example after an incremental build of the IDE that skips unchanged sources, or when the sheet classes are in a jar built against 1.0.0. There is no compilation error in that case: the first validation or generation of the class fails at run time.
java.lang.annotation.AnnotationTypeMismatchException: Incorrectly typed data found for annotation elementpublic abstract cloud.baldilorenzo.sheetsmith.style.Toggle cloud.baldilorenzo.sheetsmith.annotation.ExcelSheet.autoFilter()(Found data of type java.lang.Boolean[true])With the startup validation enabled, the application does not start.
Fix. Rebuild the application from scratch, for example with mvn clean verify, or with the rebuild command of the IDE: the compiler then reports every case of section 2.2. Jars that contain sheet classes, such as a shared library of corporate reports, must be rebuilt and published against 1.1.0 too.
Exhaustive switch on CellValue
Section titled “Exhaustive switch on CellValue”CellValue is a sealed interface, and 1.1.0 adds a seventh form, CellValue.Link, for hyperlinks. Code that switches over every form of CellValue without a default branch, typically in the tests of a converter, no longer compiles:
the switch expression does not cover all possible input values(or the switch statement does not cover ... for a switch statement).
Fix. Add the new case, or a default branch:
static String describe(CellValue value) { return switch (value) { case CellValue.Text text -> "text " + text.value(); case CellValue.Numeric numeric -> "number " + numeric.value(); case CellValue.Bool bool -> "boolean " + bool.value(); case CellValue.Date date -> "date " + date.value(); case CellValue.DateTime dateTime -> "date-time " + dateTime.value(); case CellValue.Link link -> "link " + link.value().address(); // new in 1.1.0 case CellValue.Blank blank -> "blank"; };}A switch with a default branch, and code that uses instanceof on single forms, compiles unchanged.
New built-in converters
Section titled “New built-in converters”Columns of the types listed in section 1.1 no longer need a converter. Nothing breaks:
- converters already declared on a field or registered for one of these types keep being used, because they always win over the built-in ones;
- a column of one of these types that was rejected with V-10 is now written by the built-in converter.
An application converter can be removed when the built-in representation fits: compare the two before removing it, because the representation may differ (for example Currency is written as its code, EUR, not as its symbol).
Checklist
Section titled “Checklist”- Update the version of the dependency.
- Rebuild from scratch, and fix every use of
freezeHeader,autoFilterandautoSizeColumns. - Fix every exhaustive
switchonCellValue. - Rebuild and publish the jars that contain sheet classes.
- Run the tests, and the startup validation if it is enabled.