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

Neil Roeth commented on MATH-742:
---------------------------------

{quote}
It was an example of a case where the appropriate serialization code might be 
missing. In other words, because it is so simple to add "Serializable" just in 
case, we create problems for later.
{quote}
I am not understanding what problems this could cause - can you give some 
explicit examples?  I don't know what your criteria are for "appropriate 
serialization code" - can you describe a case where the default serialization 
code is not appropriate and _why_ it is not appropriate?

As far as I can tell, the writeObject() and readObject() methods in 
ExceptionContext are unnecessary because they simply do what the default 
mechanism does anyway (except that it replaces throwing an exception for a 
non-serializable object with a String that says it is non-serializable).  What 
am I missing?

Your code for a class that serializes PolynomialSplineFunction pulls 
coefficients[] out of the underlying PolynomialFunction class and serializes 
them.  Why do that instead of just using PolynomialFunction.writeObject()?  Why 
is it better programming practice to create separate serialization classes that 
have deep knowledge of the class structure of each of its data members rather 
than encapsulate the serialization in each of those classes?  If 
PolynomialFunction implements Serializable, then either 
PolynomialFunction.writeObject() will do the right thing or it is a bug in 
PolynomialFunction's implementation of writeObject() - a serializer for 
PolynomialSplineFunction shouldn't have to take on the responsibility of 
serializing the guts of PolynomialFunction.  I don't see how breaking 
encapsulation like this is an improvement over the default mechanism, which 
doesn't break it.
                
> Please make PolynomialSplineFunction Serializable
> -------------------------------------------------
>
>                 Key: MATH-742
>                 URL: https://issues.apache.org/jira/browse/MATH-742
>             Project: Commons Math
>          Issue Type: Improvement
>    Affects Versions: 2.2
>            Reporter: Neil Roeth
>            Priority: Minor
>         Attachments: PolynomialSplineFunction.java
>
>
> PolynomialSplineFunction is not Serializable, while the very similar 
> PolynomialFunction class in the same package is. All that needs to be done is 
> to add the import:
> {{import java.io.Serializable;}}
> and change this:
> {{public class PolynomialSplineFunction implements 
> DifferentiableUnivariateRealFunction}}
> to this:
> {{public class PolynomialSplineFunction implements 
> DifferentiableUnivariateRealFunction, Serializable}}
> I made exactly that modification to a local copy and it serialized 
> successfully.  Before the change, I got serialization errors.
> Thanks.

--
This message is automatically generated by JIRA.
If you think it was sent incorrectly, please contact your JIRA administrators: 
https://issues.apache.org/jira/secure/ContactAdministrators!default.jspa
For more information on JIRA, see: http://www.atlassian.com/software/jira

        

Reply via email to