4
4
import com .fasterxml .jackson .databind .JsonNode ;
5
5
import com .linkedin .common .urn .Urn ;
6
6
import com .linkedin .data .ByteString ;
7
+ import com .linkedin .data .DataMap ;
7
8
import com .linkedin .data .template .RecordTemplate ;
8
9
import com .linkedin .entity .Aspect ;
9
10
import com .linkedin .entity .EntityResponse ;
13
14
import com .linkedin .metadata .models .registry .EntityRegistry ;
14
15
import com .linkedin .mxe .GenericAspect ;
15
16
import com .linkedin .mxe .GenericPayload ;
17
+ import java .lang .reflect .Constructor ;
18
+ import java .lang .reflect .InvocationTargetException ;
16
19
import java .nio .charset .StandardCharsets ;
17
20
import java .util .Map ;
18
21
import java .util .stream .Collectors ;
@@ -23,6 +26,22 @@ public class GenericRecordUtils {
23
26
24
27
private GenericRecordUtils () {}
25
28
29
+ public static <T extends RecordTemplate > T copy (T input , Class <T > clazz ) {
30
+ try {
31
+ if (input == null ) {
32
+ return null ;
33
+ }
34
+ Constructor <T > constructor = clazz .getConstructor (DataMap .class );
35
+ return constructor .newInstance (input .data ().copy ());
36
+ } catch (CloneNotSupportedException
37
+ | InvocationTargetException
38
+ | NoSuchMethodException
39
+ | InstantiationException
40
+ | IllegalAccessException e ) {
41
+ throw new RuntimeException (e );
42
+ }
43
+ }
44
+
26
45
/** Deserialize the given value into the aspect based on the input aspectSpec */
27
46
@ Nonnull
28
47
public static RecordTemplate deserializeAspect (
0 commit comments