You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@commons.apache.org by "Alex Herbert (Jira)" <ji...@apache.org> on 2020/01/19 12:39:00 UTC

[jira] [Commented] (CSV-248) CSVRecord is not Serializable

    [ https://issues.apache.org/jira/browse/CSV-248?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=17018900#comment-17018900 ] 

Alex Herbert commented on CSV-248:
----------------------------------

This throws a NotSerializableException.

{code:java}
@Test
public void testSerialization() throws IOException {
    CSVRecord shortRec;
    try (final CSVParser parser = CSVParser.parse("a,b", CSVFormat.newFormat(','))) {
        shortRec = parser.iterator().next();
    }
    final ByteArrayOutputStream out = new ByteArrayOutputStream();
    try (ObjectOutputStream oos = new ObjectOutputStream(out)) {
        oos.writeObject(shortRec);
    }
}
{code}


> CSVRecord is not Serializable
> -----------------------------
>
>                 Key: CSV-248
>                 URL: https://issues.apache.org/jira/browse/CSV-248
>             Project: Commons CSV
>          Issue Type: Bug
>    Affects Versions: 1.7
>            Reporter: Alex Herbert
>            Priority: Major
>
> CSVRecord is no longer Serializable as it stores the CSVParser and that is not serializable.
> The parser contains a list of all the CSVRecords. So to serialize this would serialize a lot of extra information. The cascade of serialization eventually includes the original BufferedReader used to read the data.
> The parser is required for the header map functionality and the getParser() method. The easy fix is to not support any functionality related to the parser after deserialization. If the header map functionality is to be supported the class can store the header map (easy), or overload the serialization methods to record and load the header map (more effort), or something else.
>  
>  



--
This message was sent by Atlassian Jira
(v8.3.4#803005)