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

feat(java): deserialize one pojo into another type #2012

Open
wants to merge 5 commits into
base: main
Choose a base branch
from

Conversation

orisgarno
Copy link
Contributor

@orisgarno orisgarno commented Jan 19, 2025

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

Related issues

Does this PR introduce any user-facing change?

  • Does this PR introduce any public API change?
  • Does this PR introduce any binary protocol compatibility change?

Benchmark

@@ -22,7 +22,7 @@
import org.apache.fury.type.TypeUtils;

public class ClassSpec {
public final String entireClassName;
public String entireClassName;
Copy link
Collaborator

@chaokunyang chaokunyang Jan 26, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I prefer to keep ClassDef immutable abd return a new ClassDef instead

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sure ofc, im still stuck facing exception here and there.

@orisgarno orisgarno force-pushed the serialize-pojo-to-another branch from 128b203 to 04a9e14 Compare January 29, 2025 16:07
@orisgarno
Copy link
Contributor Author

Hi @chaokunyang, need your help here.
Any idea whats wrong with the approach? seems like its able to change the parent class and serializer but somehow serializer failed to read the buffer properly? do i missed something?
image

ClassInfo classInfo = readClassInfoWithMetaShare(buffer, fury.getSerializationContext().getMetaContext());

// replace target class if needed
if (!targetClass.getName().equals(classInfo.getCls().getName())) {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
if (!targetClass.getName().equals(classInfo.getCls().getName())) {
if (targetClass != classInfo.getCls()) {

this will be much faster

ClassInfo targetClassInfo = getClassInfo(targetClass);
buildClassDef(targetClassInfo);
classInfo.classDef = ClassDef.replaceRootClassTo(this, targetClassInfo);
classInfo.serializer = createSerializer(targetClass);
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This line won't work as you expect. It just create a serializer for raw targetClass without using type info from peer class

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok I'll look into that first

@chaokunyang
Copy link
Collaborator

chaokunyang commented Jan 30, 2025

@orisgarno I make it work in 52dfea2 , you can continue the work now. And it seems the tests you write have some issues, please take a look at it.

@chaokunyang chaokunyang marked this pull request as ready for review January 30, 2025 13:29
@chaokunyang
Copy link
Collaborator

Hi @orisgarno , could you also update the user guide document about how to deserialize one type into another?

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

Successfully merging this pull request may close these issues.

2 participants