diff --git a/README.md b/README.md index 568b090..dd13794 100644 --- a/README.md +++ b/README.md @@ -15,6 +15,48 @@ **Note:** The map field must use a `LinkedHashMap` (or another ordered `Map` implementation) to guarantee deterministic column ordering. Using a `HashMap` will produce non-deterministic column order in the generated report. +### Complex Map Values ### + +Map values can be a boxed primitive or `String` (rendered as a single column, as above), or a complex object annotated with `@Reportable` members — in which case each entry expands into one column per `@Reportable` field/method on the value's class, and the map key becomes a single header spanning those columns. + +```java +public class User { + @Reportable(headerName = "First Name", column = "A") + private String firstName; + + @Reportable(headerName = "Last Name", column = "B") + private String lastName; + + @Reportable(headerName = "Salary", column = "C") + @NumberFormatter(format = "#,##0.00") + private double salary; +} + +public class Team { + @Reportable(headerName = "Team", column = "A") + private String teamName; + + @ReportableMap + private LinkedHashMap users; +} +``` + +Given a `Team` with `users = {"Primary": User("Alice", "Smith", 500.5)}`: + +- Excel: the header row is `Team | Primary` with `Primary` merged across the 3 generated columns, and the data row is ` | Alice | Smith | 500.50` — with `Salary` rendered as a formatted numeric cell via `@NumberFormatter`, exactly as it would be for a top-level `@Reportable` field. +- CSV (no concept of merged cells): the key appears in the first of the generated columns and the rest are left blank. + +``` +Team,Primary,, +,Alice,Smith,500.50 +``` + +Each nested member's own formatting annotations (`@DateFormatter`, `@NumberFormatter`, `@StringFormatFormatter`, `@StringFormatter`, `@CurrencyFormatter`, `@BooleanFormatter`, `@NullFormatter`, `@CommaFormatter`, `@TrimFormatter`) are applied the same way they would be on a top-level `@Reportable` field. + +If a value's class has no `@Reportable`-annotated members (for example an unannotated object or a `java.util.Date`), the entry falls back to the original single-column behavior, rendered via `toString()`. + +**Note:** As with top-level fields, the columns generated for each map key are determined from the *first* data row's map. If a later row's map is missing an entry for that key, or the entry is `null`, the corresponding cells are simply left blank rather than shifting the remaining columns. + Annotate reportable member variables or methods with formatters (*optional*) ```java diff --git a/TODO.md b/TODO.md index 8562315..7dafa20 100644 --- a/TODO.md +++ b/TODO.md @@ -16,6 +16,7 @@ - [x] Add test fixtures + tests (Excel): merged region assertions, nested formatting applied - [x] Run full test suite (`mvn test`) and confirm existing `ReportableMap` tests still pass — 91/91 passing - [x] Manual verification: generated a workbook from the `users` example (scratch script) — confirmed merged region A1:B1 with key "user1" as header, firstName/lastName as the two data cells beneath it +- [x] Document complex map value support in README.md (`@ReportableMap` section) — verified behavior against `Generator.java`, `ReportableMap.java`, `Reportable.java`, `ExcelGenerator.java`, and the CSV/Excel complex-value test classes ## Notes - Simple values (boxed primitive/String) and value classes with zero `@Reportable` members both fall back to today's single-column behavior — confirmed with user.