Skip to content

Commit

Permalink
Switches enumeration serializer to name based serialization
Browse files Browse the repository at this point in the history
  • Loading branch information
nvollmar committed Mar 11, 2022
1 parent 1be77ef commit b784ced
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 8 deletions.
9 changes: 5 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -359,15 +359,16 @@ Enum Serialization
------------------

Serialization of Java and Scala 3 enums is done by name (and not by index) to avoid having reordering of enum values breaking serialization.
As of 2.4, the default serializer for `scala.Enumeration` is based on index (order of definition),
which is now deprecated and will be replaced by a name base serializer for consistency with the upcoming 2.5 release.
As of 2.5.0, the default serializer for `scala.Enumeration` has been switched to a name base serializer for consistency.

To actively change current default to the new by name serializer, a custom Kryo initializer must be defined and the following override has to be done:
To change current default back to old index based (order of definition) serialization, a custom Kryo initializer must be defined and the following override has to be done:

```scala
protected override def defaultEnumerationSerializer: Class[_ <: Serializer[Enumeration#Value]] = classOf[EnumerationNameSerializer]
protected override def defaultEnumerationSerializer: Class[_ <: Serializer[Enumeration#Value]] = classOf[EnumerationSerializer]
```

Note: this serializer will be removed in the future. If needed, you can reimplement it in your own project.

Using Kryo on JDK 17
--------------------

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,10 +39,12 @@ class DefaultKryoInitializer {


/**
* Overwrite to change default enumeration serializer to [[io.altoo.akka.serialization.kryo.serializer.scala.EnumerationNameSerializer]] instead of [[io.altoo.akka.serialization.kryo.serializer.scala.EnumerationSerializer]].
* Release 2.5.0 will change default.
* Overwrite to change default enumeration serializer from [[io.altoo.akka.serialization.kryo.serializer.scala.EnumerationNameSerializer]] to old [[io.altoo.akka.serialization.kryo.serializer.scala.EnumerationSerializer]].
*
* @deprecated Will be removed with [[io.altoo.akka.serialization.kryo.serializer.scala.EnumerationSerializer]] in the future.
*/
protected def defaultEnumerationSerializer: Class[_ <: Serializer[Enumeration#Value]] = classOf[EnumerationSerializer]
@Deprecated
protected def defaultEnumerationSerializer: Class[_ <: Serializer[Enumeration#Value]] = classOf[EnumerationNameSerializer]

/**
* Registers serializer for standard/often used scala classes - override only if you know what you are doing!
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ import com.esotericsoftware.kryo.{Kryo, Serializer}
* Enumeration serializer using ordinal value.
*
* @author luben
* @deprecated For consistency use EnumerationNameSerializer instead.
* @deprecated For consistency use EnumerationNameSerializer instead - will be removed in the future.
*/
@Deprecated
class EnumerationSerializer extends Serializer[Enumeration#Value] {
Expand Down
4 changes: 4 additions & 0 deletions migration-guide.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
akka-kryo-serialization - migration guide
=========================================

Migration from 2.4.x to 2.5.x
-----------------------------
* `EnumerationSerializer` has been deprecated with 2.4.2, with 2.5.0 default serializer for `scala.Enumeration` has been switched to `EnumerationNameSerializer`, which is not backwards compatible.

Migration from 2.3.x to 2.4.x
-----------------------------
<i>No manual steps required</i>
Expand Down

0 comments on commit b784ced

Please sign in to comment.