Skip to content

Commit efba91f

Browse files
committed
Update README.md.
1 parent 5db6bd8 commit efba91f

File tree

2 files changed

+28
-1
lines changed

2 files changed

+28
-1
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -517,7 +517,7 @@ System.out.println(text); // Hello, World!
517517
```
518518

519519
## CSVEncoder
520-
The `CSVEncoder` class serializes a sequence of map or bean values to CSV. The list passed to the constructor represents both the names of the columns in the output document and the keys or properties to which those columns correspond. For example:
520+
The `CSVEncoder` class serializes a sequence of map, bean, or record values to CSV. The list passed to the constructor represents both the names of the columns in the output document and the keys or properties to which those columns correspond. For example:
521521

522522
```java
523523
var rows = listOf(

kilo-client/src/test/java/org/httprpc/kilo/io/CSVEncoderTest.java

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,13 @@ public boolean isC() {
5757
}
5858
}
5959

60+
public record Record(
61+
String a,
62+
int b,
63+
boolean c
64+
) {
65+
}
66+
6067
@Test
6168
public void testMaps() throws IOException {
6269
var rows = listOf(
@@ -109,6 +116,26 @@ public void testBeans() throws IOException {
109116
assertEquals(expected, writer.toString());
110117
}
111118

119+
@Test
120+
public void testRecords() throws IOException {
121+
var rows = listOf(
122+
new Record("hello", 123, true),
123+
new Record("goodbye", 456, false)
124+
);
125+
126+
var csvEncoder = new CSVEncoder(listOf("a", "b", "c"));
127+
128+
var writer = new StringWriter();
129+
130+
csvEncoder.write(rows, writer);
131+
132+
var expected = "\"a\",\"b\",\"c\"\r\n"
133+
+ "\"hello\",123,true\r\n"
134+
+ "\"goodbye\",456,false\r\n";
135+
136+
assertEquals(expected, writer.toString());
137+
}
138+
112139
@Test
113140
public void testFormats() throws IOException {
114141
var number = 1000.0;

0 commit comments

Comments
 (0)