4
4
import com .jsoniter .annotation .JsonCreator ;
5
5
import com .jsoniter .annotation .JsonProperty ;
6
6
import com .jsoniter .any .Any ;
7
+ import com .jsoniter .spi .ClassDescriptor ;
7
8
import com .jsoniter .spi .ClassInfo ;
8
9
import com .jsoniter .spi .JsonException ;
9
10
import junit .framework .TestCase ;
17
18
18
19
public class TestRecord extends TestCase {
19
20
20
- record TestRecord1 (long field1 ) {}
21
+ record TestRecord1 (long field1 ) {
22
+ }
21
23
22
24
public record TestRecord0 (Long id , String name ) {
23
25
@@ -114,7 +116,8 @@ public void test_record_withOnlyFieldDecoder() throws IOException {
114
116
115
117
public void test_record_2_fields_withOnlyFieldDecoder () throws IOException {
116
118
117
- record TestRecord2 (long field1 , String field2 ) {}
119
+ record TestRecord2 (long field1 , String field2 ) {
120
+ }
118
121
119
122
assertEquals (ReflectionRecordDecoder .OnlyFieldRecord .class , ReflectionDecoderFactory .create (new ClassInfo (TestRecord2 .class )).getClass ());
120
123
@@ -127,7 +130,8 @@ record TestRecord2(long field1, String field2) {}
127
130
128
131
public void test_record_2_fields_swapFieldOrder_withOnlyFieldDecoder () throws IOException {
129
132
130
- record TestRecord2 (String field2 , long field1 ) {}
133
+ record TestRecord2 (String field2 , long field1 ) {
134
+ }
131
135
132
136
assertEquals (ReflectionRecordDecoder .OnlyFieldRecord .class , ReflectionDecoderFactory .create (new ClassInfo (TestRecord2 .class )).getClass ());
133
137
@@ -140,8 +144,10 @@ record TestRecord2(String field2, long field1) {}
140
144
141
145
public void test_record_recordComposition_withOnlyFieldDecoder () throws IOException {
142
146
143
- record TestRecordA (long fieldA ) {}
144
- record TestRecordB (long fieldB , TestRecordA a ) {}
147
+ record TestRecordA (long fieldA ) {
148
+ }
149
+ record TestRecordB (long fieldB , TestRecordA a ) {
150
+ }
145
151
146
152
assertEquals (ReflectionRecordDecoder .OnlyFieldRecord .class , ReflectionDecoderFactory .create (new ClassInfo (TestRecordB .class )).getClass ());
147
153
@@ -154,7 +160,8 @@ record TestRecordB(long fieldB, TestRecordA a) {}
154
160
155
161
public void test_record_empty_constructor_withOnlyFieldDecoder () throws IOException {
156
162
157
- record TestRecord3 () {}
163
+ record TestRecord3 () {
164
+ }
158
165
159
166
assertEquals (ReflectionRecordDecoder .OnlyFieldRecord .class , ReflectionDecoderFactory .create (new ClassInfo (TestRecord3 .class )).getClass ());
160
167
@@ -216,6 +223,8 @@ public TestRecord6(@JsonProperty("valInt") int valInt) {
216
223
}
217
224
}
218
225
226
+ assertEquals (ReflectionRecordDecoder .WithCtor .class , ReflectionDecoderFactory .create (new ClassInfo (TestRecord6 .class )).getClass ());
227
+
219
228
JsonIterator iter = JsonIterator .parse ("{ 'valInt' : 1 }" .replace ('\'' , '"' ));
220
229
TestRecord6 record = iter .read (TestRecord6 .class );
221
230
@@ -227,8 +236,10 @@ public void test_record_withCtorDecoder() throws IOException {
227
236
record TestRecord2 (@ JsonProperty long field1 ) {
228
237
229
238
@ JsonCreator
230
- TestRecord2 {}
239
+ TestRecord2 {
240
+ }
231
241
}
242
+ assertEquals (ReflectionRecordDecoder .WithCtor .class , ReflectionDecoderFactory .create (new ClassInfo (TestRecord2 .class )).getClass ());
232
243
233
244
assertEquals (ReflectionDecoderFactory .create (new ClassInfo (TestRecord2 .class )).getClass (), ReflectionObjectDecoder .WithCtor .class );
234
245
@@ -237,4 +248,11 @@ record TestRecord2(@JsonProperty long field1) {
237
248
238
249
assertEquals (1 , record .field1 );
239
250
}
251
+
252
+ public void test_record_constructor () throws IOException {
253
+ ClassDescriptor desc = ClassDescriptor .getDecodingClassDescriptor (new ClassInfo (TestRecord0 .class ), false );
254
+ assertEquals (TestRecord0 .class .getConstructors ()[1 ], desc .ctor .ctor );
255
+
256
+ }
257
+
240
258
}
0 commit comments