EsotericSoftware / EsotericSoftware/kryonet

Class Not Registered: HashMap$Values

Open
#67 0 comments 0 reactions 0 assignees View on GitHub
Dominant language
Java
Stars
1.9k
Forks
411
PR merge metrics
No merged PRs in 30d

Description

I get the error "class not registered: HashMap$Values" since I use a HashMap and call .values() on it, passing the resulting Collection to a class that gets serialized and sent over the network by Kryonet / Kryo.

After some research, apparently HashMap itself is Serializable, but HashMap$Values is not, which is a private implementation class within HashMap and therefore completely inaccessible.

Although I solved this issue by doing (pseudocode) `new ArrayList (HashMap.values())` I can't figure out why Kryo's MapSerializer cannot deal with this simple use case, and would like to know if there's a better way. Surely I'm not the only person to have encountered this problem?

I tried setting registration to be optional, which gets rid of the above error, but then that just results in a NullPointerException when the resulting Collection from HashMap$Values is actually accessed, I believe after deserialization.

I've read through the Kryo docs, searched Google, and read through all the Kryo & Kryonet issues / discussions on Google Groups and GitHub to no avail.

P.S. I'm using StdInstantiatorStrategy and apparently FieldSerializer attempts to serialize the HashMap$Values class instead of MapSerializer.

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.