Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix #529: Support serializing the Enum class object #530

Merged
merged 1 commit into from
Aug 12, 2017

Conversation

magro
Copy link
Collaborator

@magro magro commented Aug 11, 2017

When an Enum.class instance is serialized (by ClassSerializer), this
causes the creation of the registered default serializer (EnumSerializer)
with this call chain:

ClassSerializer.write
 -> Kryo.writeClass
  -> DefaultClassResolver.writeClass
   -> Kryo.getDefaultSerializer
    -> ReflectionSerializerFactory.makeSerializer(kryo, EnumSerializer, Enum.class)

This is done so that Kryo.writeClass can write the class name or the id
of the serializer registration.

Until now, the EnumSerializer failed instantiation for a type with null
enum constants. This however is the case for Enum.class itself.
The creation of EnumSerializer for Enum.class is now allowed, under the
assumption that this happens in the context of the Enum.class serialization,
and that write/read on the created EnumSerializer instance will never
be called. This assumption should be safe, since there should never be an instance
of the abstract Enum class.

When an `Enum.class` instance is serialized (by `ClassSerializer`), this
causes the creation of the registered default serializer (`EnumSerializer`)
with this call chain:
```
ClassSerializer.write
 -> Kryo.writeClass
  -> DefaultClassResolver.writeClass
   -> Kryo.getDefaultSerializer
    -> ReflectionSerializerFactory.makeSerializer(kryo, EnumSerializer, Enum.class)
```

This is done so that `Kryo.writeClass` can write the class name or the id
of the serializer registration.

Until now, the `EnumSerializer` failed instantiation for a type with `null`
enum constants. This however is the case for `Enum.class` itself.
The creation of `EnumSerializer` for `Enum.class` is now allowed, under the
assumption that this happens in the context of the `Enum.class` serialization,
and that `write`/`read` on the created `EnumSerializer` instance will never
be called. This assumption should be safe, since there should never be an instance
of the abstract `Enum` class.
@magro magro merged commit 7354009 into EsotericSoftware:master Aug 12, 2017
@pardom
Copy link

pardom commented Feb 2, 2018

Is this fix in the snapshots repo yet?

@magro
Copy link
Collaborator Author

magro commented Feb 4, 2018

@ParDonut yes it should.

@magro
Copy link
Collaborator Author

magro commented Mar 20, 2018

@ParDonut It got also just released with 4.0.2

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging this pull request may close these issues.

2 participants