8
8
import java .lang .reflect .InvocationTargetException ;
9
9
import java .lang .reflect .Type ;
10
10
import java .util .*;
11
+ import java .util .function .BiFunction ;
11
12
import java .util .function .Function ;
12
13
13
14
import static com .alibaba .fastjson2 .JSONB .Constants .BC_NULL ;
@@ -20,6 +21,8 @@ public class ObjectReaderNoneDefaultConstructor<T>
20
21
final Function <Map <Long , Object >, T > creatorFunction ;
21
22
final Map <Long , FieldReader > paramFieldReaderMap ;
22
23
final Constructor noneDefaultConstructor ;
24
+ final BiFunction bifunction ;
25
+ final Function function ;
23
26
24
27
public ObjectReaderNoneDefaultConstructor (
25
28
Class objectClass ,
@@ -60,6 +63,13 @@ public ObjectReaderNoneDefaultConstructor(
60
63
} else {
61
64
noneDefaultConstructor = null ;
62
65
}
66
+ if (creator instanceof ConstructorFunction ) {
67
+ bifunction = ((ConstructorFunction <T >) creator ).biFunction ;
68
+ function = ((ConstructorFunction <T >) creator ).function ;
69
+ } else {
70
+ bifunction = null ;
71
+ function = null ;
72
+ }
63
73
}
64
74
65
75
static FieldReader [] concat (FieldReader [] a , FieldReader [] b ) {
@@ -536,6 +546,12 @@ typeName, getObjectClass(), features | getFeatures()
536
546
537
547
public T createInstance (Object [] args ) {
538
548
try {
549
+ if (function != null ) {
550
+ return (T ) function .apply (args [0 ]);
551
+ }
552
+ if (bifunction != null ) {
553
+ return (T ) bifunction .apply (args [0 ], args [1 ]);
554
+ }
539
555
return (T ) noneDefaultConstructor .newInstance (args );
540
556
} catch (InstantiationException | IllegalAccessException | IllegalArgumentException |
541
557
InvocationTargetException e ) {
0 commit comments