Skip to content

Commit 31c4c3b

Browse files
Copilotozlerhakan
andcommitted
Add documentation for Java Records support
Co-authored-by: ozlerhakan <[email protected]>
1 parent c9a9b09 commit 31c4c3b

File tree

1 file changed

+51
-0
lines changed

1 file changed

+51
-0
lines changed

README.adoc

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -203,6 +203,57 @@ PoijiOptions options = PoijiOptionsBuilder.settings()
203203
1. Poiji should look at the second (zero-based index) sheet of your excel file.
204204
== Documentation
205205

206+
=== Java Records Support
207+
208+
Starting with version 4.9.0, Poiji supports Java Records (Java 16+). Records provide a concise way to declare data carrier classes with immutable fields.
209+
210+
[source,java]
211+
----
212+
public record EmployeeRecord(
213+
@ExcelCellName("ID")
214+
long employeeId,
215+
216+
@ExcelCellName("NAME")
217+
String name,
218+
219+
@ExcelCellName("SURNAME")
220+
String surname,
221+
222+
@ExcelCellName("AGE")
223+
int age,
224+
225+
@ExcelCellName("SINGLE")
226+
boolean single,
227+
228+
@ExcelRow
229+
int row
230+
) {}
231+
----
232+
233+
Use records just like regular classes with Poiji:
234+
235+
[source,java]
236+
----
237+
List<EmployeeRecord> employees = Poiji.fromExcel(
238+
new File("employees.xlsx"),
239+
EmployeeRecord.class
240+
);
241+
242+
EmployeeRecord firstEmployee = employees.get(0);
243+
// Access fields using record accessor methods
244+
System.out.println(firstEmployee.name());
245+
System.out.println(firstEmployee.age());
246+
----
247+
248+
Records work with all annotations including:
249+
250+
* `@ExcelCell` - Map by column index
251+
* `@ExcelCellName` - Map by column name
252+
* `@ExcelRow` - Capture row number
253+
* `@ExcelUnknownCells` - Capture unmapped cells
254+
255+
Records work with both XLS and XLSX formats and support all standard Poiji options.
256+
206257
=== Prefer Default Value
207258

208259
If you want a date field to return `null` rather than a default date, use `PoijiOptionsBuilder` with the `preferNullOverDefault` method as follows:

0 commit comments

Comments
 (0)