When you send data on an object stream, it will send each object only once. This means if you modify and object and send it multiple times, you need to either use writeUnshared(mutableObject) or reset() which clears the cache of objects already sent.


You can't create an ObjectOutput/InputStream repeatly. If you want to make sure data is sent instead of buffered use flush(). If you are sending data like int instead of Objects, try DataOutput/InputStream.

Answer from Peter Lawrey on Stack Overflow
🌐
Stack Overflow
stackoverflow.com › questions › 63275614 › how-do-objectoutput-objectinput-streams-work
java - How do ObjectOutput/ObjectInput Streams work? - Stack Overflow
Then, the constituent parts are sent along the wire (that is, take the object, and any fields that are primitives can just be sent; ObjectOutputStream knows how to send an int intrinsically, for example. Any other types are sent by, in turn, asking THAT object's class to do so).
🌐
Coding Shuttle
codingshuttle.com › home › handbooks › java programming handbook › objectinputstream and objectoutputstream
ObjectInputStream and ObjectOutputStream | Coding Shuttle
April 9, 2025 - ObjectOutputStream: Used to serialize Java objects into a stream of bytes and write them to an OutputStream (like a file).
Discussions

java - Why does ObjectOutputStream.writeObject not take a Serializable? - Stack Overflow
The ObjectOutput interface specifies methods that allow objects to be written to a stream or underlying storage, but this may be achieved by a process other than serialization. The ObjectOutputStream implements this functionality, but requires serializable objects. More on stackoverflow.com
🌐 stackoverflow.com
java - Why does ObjectOutputStream write symbols to a file instead of my input? - Stack Overflow
I am trying to write my ArrayList, named Clients, to a file. It works, but unfortunately it just writes symbols into the file and not my actual input. Below is my code: public void SaveToFile... More on stackoverflow.com
🌐 stackoverflow.com
Slow object persistance using objectoutputstream.writeobject
Oracle Forums is a community platform where you can discuss Oracle products and services, collaborate with peers, and connect with Oracle experts. More on forums.oracle.com
🌐 forums.oracle.com
java - difference between "DataOutputStream" and "ObjectOutputStream" - Stack Overflow
I'm a beginner programmer following this Java Tutorial. In the Basic I/O section, two of the classes mentioned are Data Streams and Object Streams. They are used very similarily: out = new More on stackoverflow.com
🌐 stackoverflow.com
🌐
Oracle
docs.oracle.com › en › java › javase › 17 › docs › specs › serialization › output.html
Java Object Serialization Specification: 2 - Object Output Classes
April 15, 2025 - If writeObject is used to write an object that has been previously written with writeUnshared, the previous writeUnshared operation is treated as if it were a write of a separate object. In other words, ObjectOutputStream will never generate back-references to object data written by calls to ...
🌐
Oracle
docs.oracle.com › en › java › javase › 11 › docs › api › › java.base › java › io › ObjectOutput.html
ObjectOutput (Java SE 11 & JDK 11 )
July 15, 2025 - ObjectOutputStream · public interface ObjectOutput extends DataOutput, AutoCloseable · ObjectOutput extends the DataOutput interface to include writing of objects. DataOutput includes methods for output of primitive types, ObjectOutput extends that interface to include objects, arrays, and ...
🌐
Baeldung
baeldung.com › home › java › java io › guide to java outputstream
Guide to Java OutputStream | Baeldung
December 3, 2025 - ObjectOutputStream can write primitive data types and graphs of Java objects to a destination.
Find elsewhere
Top answer
1 of 2
20

This is because writeObject in ObjectOutputStream overrides the method in the ObjectOutput interface which does not require that the object be Serializable.

The ObjectOutput interface specifies methods that allow objects to be written to a stream or underlying storage, but this may be achieved by a process other than serialization. The ObjectOutputStream implements this functionality, but requires serializable objects. However, it cannot modify the signature of the interface that it implements.

2 of 2
5

It should be ObjectOutputStream.writeObject(serializable) rather than ObjectOutputStream. writeObject(Object). It is a proper use case where a marker interface like Serializable should have been used but unfortunately not. This would have made it possible the very real benefit of compile-time type checking instead of failing at runtime if the object does not implement Serializable interface.

I would like to take this opportunity to mention what Joshua Bloch has mentioned in his book Effective java:

A marker interface is an interface that contains no method declarations, but merely designates (or “marks”) a class that implements the interface as having some property. For example, consider the Serializable interface. By implementing this interface, a class indicates that its instances can be written to an ObjectOutputStream (or “serialized”).

In the case of the Serializable marker interface, the ObjectOutputStream.write(Object) method will fail if its argument does not implement the interface. Inexplicably, the authors of the ObjectOutputStream API did not take advantage of the Serializable interface in declaring the write method. The method’s argument type should have been Serializable rather than Object. As it stands, an attempt to call ObjectOutputStream.write on an object that doesn’t implement Serializable will fail only at runtime, but it didn’t have to be that way.

🌐
Scientech Easy
scientecheasy.com › home › blog › objectoutputstream in java
ObjectOutputStream in Java - Scientech Easy
February 11, 2025 - In other words, an ObjectOutputStream is an output stream that serializes primitive type values, strings, and objects to a stream.
🌐
Oracle
docs.oracle.com › javase › 8 › docs › api › java › io › class-use › ObjectOutput.html
Uses of Interface java.io.ObjectOutput (Java Platform SE 8 )
Submit a bug or feature For further API reference and developer documentation, see Java SE Documentation. That documentation contains more detailed, developer-targeted descriptions, with conceptual overviews, definitions of terms, workarounds, and working code examples.
🌐
Scijava
javadoc.scijava.org › Java9 › java › io › ObjectOutput.html
ObjectOutput (Java SE 9 & JDK 9 )
ObjectOutputStream · public interface ObjectOutput extends DataOutput, AutoCloseable · ObjectOutput extends the DataOutput interface to include writing of objects. DataOutput includes methods for output of primitive types, ObjectOutput extends that interface to include objects, arrays, and ...
🌐
Oracle
forums.oracle.com › ords › apexds › post › slow-object-persistance-using-objectoutputstream-writeobjec-4254
Slow object persistance using objectoutputstream.writeobject
Oracle Forums is a community platform where you can discuss Oracle products and services, collaborate with peers, and connect with Oracle experts.
🌐
Tutorialspoint
tutorialspoint.com › java › io › objectoutputstream_writeobject.htm
Java - ObjectOutputStream writeObject(Object obj) method
The Java ObjectOutputStream writeObject(Object obj) method writes the specified object to the ObjectOutputStream. The class of the object, the signature of the class, and the values of the non-transient and non-static fields of the class and all of its supertypes are written.
🌐
GeeksforGeeks
geeksforgeeks.org › java › java-io-objectoutputstream-class-java-set-1
Java.io.ObjectOutputStream Class in Java | Set 1 - GeeksforGeeks
September 12, 2023 - An ObjectOutputStream writes primitive data types and graphs of Java objects to an OutputStream. The objects can be read (reconstituted) using an ObjectInputStream.
🌐
Microsoft Learn
learn.microsoft.com › en-us › dotnet › api › java.io.objectoutputstream
ObjectOutputStream Class (Java.IO) | Microsoft Learn
An ObjectOutputStream writes primitive data types and graphs of Java objects to an OutputStream. The objects can be read (reconstituted) using an ObjectInputStream. Persistent storage of objects can be accomplished by using a file for the stream.
🌐
Programiz
programiz.com › java-programming › objectoutputstream
Java ObjectOutputStream (With Examples)
Basically, the ObjectOutputStream encodes Java objects using the class name and object values. And, hence generates corresponding streams.
🌐
TheServerSide
theserverside.com › blog › Coffee-Talk-Java-News-Stories-and-Opinions › ObjectOutputStream-example-Learn-Java-object-serialization
ObjectOutputStream example: A Java object serialization tutorial
In this Java serialization example, we will use both the ObjectOutputStream and the ObjectInputStream to save and retrieve the state of a simple JavaBean.