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

[Java] Deserializing one pojo into another type #1998

Open
chaokunyang opened this issue Jan 8, 2025 · 4 comments
Open

[Java] Deserializing one pojo into another type #1998

chaokunyang opened this issue Jan 8, 2025 · 4 comments

Comments

@chaokunyang
Copy link
Collaborator

chaokunyang commented Jan 8, 2025

Feature Request

Continuing the discussion in #1972 (comment), we need to support deserializing one pojo into another type without the need to register class

Is your feature request related to a problem? Please describe

#1972

Describe the solution you'd like

Step1 Extend ClassDef to replace type

  /**
   * Return a new {@link ClassDef} by replacing {@code definedClass} of all fields and current {@link ClassSpec} in hierarchy 
   * from {@code cls} into {@code targetCls}.
   */
  public ClassDef replace(Class<?> cls, Class<?> targetCls) {

  }

Step2

  • Extend ClassResolver with a new readClassInfoWithMetaShare method with passed deserialized type
  • The readClassInfoWithMetaShare should return the original ClassDef first, then invoke ClassDef#replace to return a new ClassDef
  • Use that new ClassDef to create a new Deserializer to deserialize the data into passed deserialized type

Describe alternatives you've considered

No response

Additional context

#1996

@chaokunyang
Copy link
Collaborator Author

cc @orisgarno

@orisgarno
Copy link
Contributor

will start this in few days

@orisgarno
Copy link
Contributor

@chaokunyang im currenty working on it.
but do you have any idea why we need the original class(cls) public ClassDef replace(Class<?> cls, Class<?> targetCls)?
we can get from the classid from metashare? or do i miss something here?

@chaokunyang
Copy link
Collaborator Author

chaokunyang commented Jan 18, 2025

We don't need the original class, we could add a method like replaceRootClassTo(Class <?> cls)

chaokunyang added a commit that referenced this issue Feb 1, 2025
<!--
**Thanks for contributing to Fury.**

**If this is your first time opening a PR on fury, you can refer to
[CONTRIBUTING.md](https://github.com/apache/fury/blob/main/CONTRIBUTING.md).**

Contribution Checklist

- The **Apache Fury (incubating)** community has restrictions on the
naming of pr titles. You can also find instructions in
[CONTRIBUTING.md](https://github.com/apache/fury/blob/main/CONTRIBUTING.md).

- Fury has a strong focus on performance. If the PR you submit will have
an impact on performance, please benchmark it first and provide the
benchmark result here.
-->

## What does this PR do?
replace class def if target class is different type with the actual
serialized one, so it can be deserialized to another type
#1998
<!-- Describe the purpose of this PR. -->

## Related issues

<!--
Is there any related issue? Please attach here.

- #xxxx0
- #xxxx1
- #xxxx2
-->

## Does this PR introduce any user-facing change?

<!--
If any user-facing interface changes, please [open an
issue](https://github.com/apache/fury/issues/new/choose) describing the
need to do so and update the document if necessary.
-->

- [ ] Does this PR introduce any public API change?
- [ ] Does this PR introduce any binary protocol compatibility change?

## Benchmark

<!--
When the PR has an impact on performance (if you don't know whether the
PR will have an impact on performance, you can submit the PR first, and
if it will have impact on performance, the code reviewer will explain
it), be sure to attach a benchmark data here.
-->

---------

Co-authored-by: chaokunyang <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants