[Java] object deep copy into different type

Aperta
#1,975 2 commenti 0 reazioni 0 assegnatari Vedi su GitHub

I maintainer di solito rispondono entro 1 giorno

Nessuno ha ancora preso questa issue.

Valutazione

Difficoltà
5/5
Tempo stimato
Più di una settimana
Idoneità per principianti
25/100
Tipo di issue
Funzionalità
Chiarezza
Da chiarire
Stato di attività
Ferma
Stack tecnologico
java
Ambito
backend

Direzione di ricerca

Non sono indicati file sorgente, test o punti di ingresso. Inizia tracciando l’attuale meccanismo di copia profonda degli oggetti e consulta discussions/1973 e pull/1974 per l’API prevista e i vincoli di progettazione. Il lavoro è completo quando supporta la copia profonda diretta tra tipi diversi, preserva i campi corrispondenti nell’esempio e non usa il passaggio attraverso il buffer di serializzazione.

Scritto dal modello di indicizzazione a partire dal testo della issue.

Descrizione

enhancement
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

https://github.com/apache/fury/discussions/1973
https://github.com/apache/fury/pull/1974

Lingua principale
Java
Stelle
4.6k
Fork
470
Merge medio
9h 28m
PR unite (30g)
33

Preparare l'ambiente

Come iniziare

  1. Leggi tutta la issue e poi la guida ai contributi del progetto.
  2. Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
  3. Fai un fork del repository e lavora su un branch.
  4. Apri una pull request che faccia riferimento al numero della issue.

Altre issue di apache/fory

Tutte le issue di apache/fory

Issue simili

Altre issue su Java

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.