[SOLVED] How to save IOObject to repository

StaryVena
StaryVena New Altair Community Member
edited November 5 in Community Q&A
Hello,
I would like to save IOObjects from ImageProcessing extension to repository, but ImagePlus class, which is essential class in ImageProcessing IOObject, doesn't support serialization. How to serialize image is described in http://imagej.1557.n6.nabble.com/Re-ImagePlus-Serializable-td3681988.html. In AbstractIOObject is write() method, but it has final modifier so it can't be overridden.
Is there a way how to implement my own serialization and de-serialization method? Or is there other solution?

I greet and thank you for your answers.
Vaclav

Answers

  • StaryVena
    StaryVena New Altair Community Member
    No one? Does it means, that there is no solution?
  • Marco_Boeck
    Marco_Boeck New Altair Community Member
    Hi,

    I've never used it, but the Serializable interface JavaDoc says:

    Classes that require special handling during the serialization and deserialization process must implement special methods with these exact signatures:

    private void writeObject(java.io.ObjectOutputStream out)
        throws IOException
    private void readObject(java.io.ObjectInputStream in)
        throws IOException, ClassNotFoundException;
    private void readObjectNoData()
        throws ObjectStreamException;

    You could try to handle your special cases there.

    Regards,
    Marco
  • StaryVena
    StaryVena New Altair Community Member
    Hello Marco,
    I know this method, but I would like to save an image to the repository by clicking on "Store this result in the repository." (highlighted  in the picture) and I'm pretty sure that method writeObject(java.io.ObjectOutputStream out) will not be called.

    image

    So, is there any way to do this?

    Thanks,
    Vaclav
  • StaryVena
    StaryVena New Altair Community Member
    Hello,
    I hope that Simon could know answer to this problem  :)

    Thanks,
    Vaclav
  • Marco_Boeck
    Marco_Boeck New Altair Community Member
    Hi,

    let's trace what happens when you click that button.

    1. StoreInRepositoryAction#actionPerformed(ActionEvent e)
    2. RepositoryManager#store(IOObject ioobject, RepositoryLocation location, Operator callingOperator, ProgressListener progressListener)
    3. Folder#createIOObjectEntry(String name, IOObject ioobject, Operator callingOperator, ProgressListener progressListener)
    4. IOObjectEntry#storeData(IOObject data, Operator callingOperator, ProgressListener l)
    5. IOObjectSerializer#serialize(OutputStream out, Object object)
    6. IOObjectSerializer#serialize(OutputStream out, Object object, SerializationType serializationType)
    7. BodySerializer#serialize(Object object, OutputStream out) aka in this case XMLBodySerializer#serialize(Object object, OutputStream out)
    8. XMLSerialization#writeXML(Object object, OutputStream out)
    9. ObjectOutputStream#writeObject(Object obj)
    See JavaDoc of method in step 9 which is a standard serialization method offered by Java. So it should indeed use your custom writeObject(ObjectOutputStream out) method and the other 2 I mentioned earlier. Did you try it and it did not work?

    Regards,
    Marco
  • StaryVena
    StaryVena New Altair Community Member
    Hello,
    thank you. Now I see, how it works.

    Vaclav