apache / apache/fory

[Java] add more defensive version of deserialize(byte, class)

Open
#2,391 6 comments 0 reactions 0 assignees View on GitHub
enhancement
Dominant language
Java
Stars
4.5k
Forks
443
Avg merge
5h 59m
Merged PRs (30d)
77

Description

### Feature Request

I debugged the method deserialize(byte, class) and found that it does not check the deserialized data matches the class - that it just info for the compiler to know what the expected return type is.
Would it be possible to add a deserializeWithClassCheck(byte, class) that validates the byte data has a class marker saved into the byte data and that class data relates to a class that is the class expected (the one passed in the parameter list of deserializeWithClassCheck) or a subclass?

### Is your feature request related to a problem? Please describe

The idea is that users who have a secure network can avoid registering all the classes that they need on the Fory instance but have the deserializeWithClassCheck call validate the encoded data is not related to some unexpected class.
deserialize(byte, class) will deserialize and you will get a Class Cast Exception but it is good to have a method that avoids creating class instances when the encoded data is of wrong type.

### Describe the solution you'd like

_No response_

### Describe alternatives you've considered

_No response_

### Additional context

_No response_

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.