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] object deep copy into different type #1975

Open
chaokunyang opened this issue Dec 9, 2024 · 1 comment
Open

[Java] object deep copy into different type #1975

chaokunyang opened this issue Dec 9, 2024 · 1 comment

Comments

@chaokunyang
Copy link
Collaborator

Feature Request

We've supported object deep copy of object from one instance to another instance, but we still don't support deep copy object from one type into another type.

Is your feature request related to a problem? Please describe

deep copy object from one type into another type:

class Struct1 {
  int f1;
  String f2;

  public Struct1(int f1, String f2) {
    this.f1 = f1;
    this.f2 = f2;
  }
}

class Struct2 {
  int f1;
  String f2;
  double f3;
}

Struct1 s1 = xxx;
Struct2 struct2 = copyTo(s1, Struct2.class)

Describe the solution you'd like

Extend the current object deep copy mechanism

Describe alternatives you've considered

Mock by:

public class StructMappingExample {
  static class Struct1 {
    int f1;
    String f2;

    public Struct1(int f1, String f2) {
      this.f1 = f1;
      this.f2 = f2;
    }
  }

  static class Struct2 {
    int f1;
    String f2;
    double f3;
  }

  static ThreadSafeFury fury1 = Fury.builder()
    .withCompatibleMode(CompatibleMode.COMPATIBLE).buildThreadSafeFury();
  static ThreadSafeFury fury2 = Fury.builder()
    .withCompatibleMode(CompatibleMode.COMPATIBLE).buildThreadSafeFury();

  static {
    fury1.register(Struct1.class);
    fury2.register(Struct2.class);
  }

  public static void main(String[] args) {
    Struct1 struct1 = new Struct1(10, "abc");
    Struct2 struct2 = (Struct2) fury2.deserialize(fury1.serialize(struct1));
    Assert.assertEquals(struct2.f1, struct1.f1);
    Assert.assertEquals(struct2.f2, struct1.f2);
    struct1 = (Struct1) fury1.deserialize(fury2.serialize(struct2));
    Assert.assertEquals(struct1.f1, struct2.f1);
    Assert.assertEquals(struct1.f2, struct2.f2);
  }
}

This will work, but not that efficient cause it will write/read buffer.

Additional context

#1973
#1974

@chaokunyang
Copy link
Collaborator Author

Hi @zhaommmmomo , would you like to take over this issue?

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

1 participant