GoConqr hat ein neues Design! Sag uns, wie es dir gefällt.

Mindmap

Serialization

Abdelkrim ZAHMOUNI Englisch

Inhalt der Mindmap

Serialization

  1. Save this object and all of its non transient instance variables

    • new ObjectOutputStream(new FileOutputStream("f.out")).writeObject(Object) // serialize and write
      • NotSerializableException if Object non transiant graphs are not all serializable
    • new ObjectInputStream(new FileInputStream("f.in")).readObject() // read and deserialize
    • private methods to implement, if present, will be invoked automatically during serialization and deserialization
      • private void writeObject(ObjectOutputStream os) { }
      • private void readObject(ObjectInputStream is) { }
      • os.defaultWriteObject(); & is.defaultReadObject(); represent the normal serialization process for this object
      • os.writeInt(theCollar.getCollarSize()); theCollar = new Collar(is.readInt());
      • I/O-related methods writeObject() can throw exceptions. You can declare them or handle them but we recommend handling them.
      • Read the extra stuff in the same order you wrote it
      • common reason: save some part of an object's state manually
  2. Object does NOT implement Serializable

  3. Class B extends A and A is Serializable => B is Serializable

  4. Deserialization process

    • The constructor does not run, and instance variables are NOT given their initially assigned values
    • Transient instance variables get the default value according to their types
    • Instance variables INHERITED from NOT serializable classe are reset to the values they were given during the original construction of the object: the nonserializable class no-argument constructor WILL run, if no such constructor InvalidClassException
  5. collection interfaces are not serializable but concrete collection classes in java API are

  6. If you serialize an object using one version of the class, but attempt to deserialize it using a newer, different version of the class, deserialization might fail

  7. Rules

    • Object Graphs (dependencies hierarchy) should all be serializable; Otherwise transient keyword should be used to skip instance variables of non serializable types
      • We can subclass but it is not always an option
        • The class might be final
        • The class might itself refer to other non-serializable objects, and without knowing the internal structure
        • Other reasons related to your design
    • Not for statics
    • Collection/Array: every element must be serializable

Informationen

Beschreibung
Mindmap am Serialization, erstellt von Abdelkrim ZAHMOUNI am 04/10/2018.
Erstellt von
Abdelkrim ZAHMOUNI
Aufrufe
0
Verlauf
  • Erstellt von Abdelkrim ZAHMOUNI · 23 Sep 2018
  • Kopiert von Abdelkrim ZAHMOUNI · 3 Okt 2018
  • Kopiert von Abdelkrim ZAHMOUNI · 4 Okt 2018
Bewertung

Feedback

Worum geht es?

Wie gefällt dir das neue Design?

Dein Eindruck