Java 9 Compact String Serialization-deserialization & data transfer
Asked Answered
B

2

6

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?

Bondmaid answered 23/8, 2017 at 5:7 Comment(1)
String has a special representation in serialization streams. This representation never changes. So you can safely serialize and deserialize strings. See docs.oracle.com/javase/6/docs/platform/serialization/spec/…Melina
L
6

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.

Licht answered 23/8, 2017 at 5:21 Comment(0)
S
5

You can rely on Java not breaking something as basic as this. For example, String is usually serialized via DataOutput.writeUTF(). This representation has not changed.

Salep answered 23/8, 2017 at 8:35 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.