Skip to content

Commit e3eca25

Browse files
committed
[CSV-248] CSVRecord is not Serializable.
Make field transient.
1 parent 07101a9 commit e3eca25

3 files changed

Lines changed: 17 additions & 2 deletions

File tree

src/changes/changes.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@
4848
<action issue="CSV-245" type="fix" dev="ggregory" due-to="Alex Herbert">Post 1.7 release fixes.</action>
4949
<action issue="CSV-252" type="fix" dev="ggregory" due-to= "Alex Herbert">Upgrade test framework to JUnit 5 Jupiter #49, #50.</action>
5050
<action issue="CSV-247" type="fix" dev="ggregory" due-to="Alex Herbert, Gary Gregory">A single empty header is allowed when not allowing empty column headers. #47.</action>
51+
<action issue="CSV-248" type="fix" dev="ggregory" due-to="Alex Herbert">CSVRecord is not Serializable.</action>
5152
<action type="fix" dev="ggregory" due-to="Alex Herbert">Use test scope for supercsv #48.</action>
5253
<action type="update" dev="ggregory" due-to="Gary Gregory">Update tests from H2 1.4.199 to 1.4.200.</action>
5354
<action type="update" dev="ggregory" due-to="Gary Gregory">Update tests from Hamcrest 2.1 to 2.2.</action>

src/main/java/org/apache/commons/csv/CSVRecord.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ public final class CSVRecord implements Serializable, Iterable<String> {
4646
private final String[] values;
4747

4848
/** The parser that originates this record. */
49-
private final CSVParser parser;
49+
private final transient CSVParser parser;
5050

5151
CSVRecord(final CSVParser parser, final String[] values, final String comment, final long recordNumber,
5252
final long characterPosition) {

src/test/java/org/apache/commons/csv/CSVRecordTest.java

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,9 @@
2323
import static org.junit.jupiter.api.Assertions.assertThrows;
2424
import static org.junit.jupiter.api.Assertions.assertTrue;
2525

26+
import java.io.ByteArrayOutputStream;
2627
import java.io.IOException;
28+
import java.io.ObjectOutputStream;
2729
import java.io.StringReader;
2830
import java.util.ArrayList;
2931
import java.util.Collections;
@@ -58,7 +60,7 @@ record = parser.iterator().next();
5860
headerMap = parser.getHeaderMap();
5961
}
6062
}
61-
63+
6264
@Test
6365
public void testGetInt() {
6466
assertEquals(values[0], record.get(0));
@@ -184,6 +186,18 @@ public void testRemoveAndAddColumns() throws IOException {
184186
}
185187
}
186188

189+
@Test
190+
public void testSerialization() throws IOException {
191+
CSVRecord shortRec;
192+
try (final CSVParser parser = CSVParser.parse("a,b", CSVFormat.newFormat(','))) {
193+
shortRec = parser.iterator().next();
194+
}
195+
final ByteArrayOutputStream out = new ByteArrayOutputStream();
196+
try (ObjectOutputStream oos = new ObjectOutputStream(out)) {
197+
oos.writeObject(shortRec);
198+
}
199+
}
200+
187201
@Test
188202
public void testToMap() {
189203
final Map<String, String> map = this.recordWithHeader.toMap();

0 commit comments

Comments
 (0)