EsotericSoftware / EsotericSoftware/kryo

Recommendation for CompatibleFieldSerializer

Open
#684 3 comments 0 reactions 0 assignees View on GitHub
question
Dominant language
HTML
Stars
6.5k
Forks
841
Avg merge
39m
Merged PRs (30d)
4

Description

I read the example in #643, and I see that in @NathanSweet last comment says when decode `SomeClass#anotherClass` but `AnotherClass`'s structure is missing, it will cause decode failure. Because `CompatibleFieldSerializer` serialize is great depandency in order. When reading, the `AnotherClass` class doesn't exist, Kryo will skip `AnotherClass` 's chunked input buffer.
See `CompatibleFieldSerializer#read`'s `readUnknownTagData` part down below.

```
Registration registration;
try {
registration = kryo.readClass(fieldInput);
} catch (KryoException ex) {
if (!chunked)
throw new KryoException("Unable to read unknown data (unknown type). (" + getType().getName() + ")", ex);
if (DEBUG) debug("kryo", "Unable to read unknown data (unknown type).", ex);
inputChunked.nextChunk();
continue;
}
```

But the information of `SomeClass#value` is still int that buffer, so if we continue read the remaing buffer that we can cache the `SomeClass#value` in `SomeClass#anotherClass`'s chunked input.
So I simply do that:
```
Registration registration;
try {
registration = kryo.readClass(fieldInput);
} catch (KryoException ex) {
if (!chunked)
throw new KryoException("Unable to read unknown data (unknown type). (" + getType().getName() + ")", ex);
if (DEBUG) debug("kryo", "Unable to read unknown data (unknown type).", ex);
//inputChunked.nextChunk();
//continue;
registration = kryo.getRegistration(Object.class);
}
```

If Kryo can't find the Class so we give it a default Class that has no field in it, then Kryo successfully read the remaing byte in buffer and cache the `SomeClass#value` in `SomeClass#anotherClass`'s chunked input.

This change is usefull in my case, but I don't know it will have impact for other case? Or you consider add this change (maybe with configurable) in futrue release?

Looking forward to your reply.

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.