Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Java 9 Compact String Serialization-deserialization & data transfer

In Java 9 the internal representation of String has been changed from char array to byte array.

Consider I'm serializing my String data on a system running Java 9 and then attempt to deserialize it on a Java 8 system. Also consider the vice-versa situation.

One more situation that I can think of is String data being transmitted across Java 8 and Java 9 systems using RMI or JMS.

How could these scenarios possibly work? Are all the methods handling String being upgraded to handle such scenarios?

like image 554
Curious Coder Avatar asked Aug 23 '17 05:08

Curious Coder


People also ask

Can you explain serialization and deserialization in Java?

Serialization is a mechanism of converting the state of an object into a byte stream. Deserialization is the reverse process where the byte stream is used to recreate the actual Java object in memory. This mechanism is used to persist the object. The byte stream created is platform independent.

Is Java serialization deprecated?

The proposal is that serialization be removed in a phased manner, as follows. In a JDK 7 update, possibly update 6, the Serializable , ObjectInputStream , ObjectOutputStream , and associated classes in the java.io package will be deprecated.

How do you deserialize a string in Java?

For serializing the object, we call the writeObject() method of ObjectOutputStream class, and for deserialization we call the readObject() method of ObjectInputStream class. We must have to implement the Serializable interface for serializing the object.

What is Deserialized?

Deserialization is the process of reconstructing a data structure or object from a series of bytes or a string in order to instantiate the object for consumption. This is the reverse process of serialization, i.e., converting a data structure or object into a series of bytes for storage or transmission across devices.


1 Answers

While it is true that the in-memory representation of String has changed, its Serializable representation has not. Have you actually tried to serialize a String in Java 9 and deserialize it back in Java 8? I don't think you'll run into any problems.

like image 194
Gili Avatar answered Oct 21 '22 22:10

Gili