Search code examples
javaserializationcasuima

How to serialize UIMA CAS combined with Java Serialization


I have these classes:

class DocumentObj implements Serializable {
    ...
    List<SentenceObj> sentenceObjs;
    JCas docJcas;
}
class SentenceObj implements Serializable {
    ...
    annotation.Sentence sentenceAnnotation;
}

I would like to dump each DocumentObj as a file on disk, using the default Java serialization. Later they would also be deserialized back into the Java objects. I understand I would need some special treatment for the JCases and the Sentence Annotations as they are not serializable (now I get NotSerializableException). Hopefully the treatment could be as minimal as possible.

How do you suggest to do this, regarding serialization of JCas and combining it with Java serialization?

I am working on Windows, with Java 1.6 and UIMA 2.4.0. I am using the same type system and the same 3 views for all JCases and annotations.


Solution

  • Don't use default Java serialization. Use instead the org.apache.uima.cas.impl.Serialization utilities, or even better the BinaryCasWriter from DK-pro.