Skip to content

Commit e09fa39

Browse files
committed
test - example of use of another constructor for record decoding (#16)
1 parent ac59b48 commit e09fa39

File tree

1 file changed

+18
-4
lines changed

1 file changed

+18
-4
lines changed

src/test/java/com/jsoniter/TestRecord.java

Lines changed: 18 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,8 @@
99
import junit.framework.TestCase;
1010

1111
import java.io.IOException;
12-
import java.lang.reflect.Constructor;
13-
import java.lang.reflect.Field;
14-
import java.lang.reflect.Method;
15-
import java.lang.reflect.Modifier;
12+
import java.lang.reflect.*;
13+
import java.util.Arrays;
1614
import java.util.Map;
1715

1816
public class TestRecord extends TestCase {
@@ -203,6 +201,22 @@ public TestRecord6(int valInt) {
203201
assertNotNull(record);
204202
}
205203

204+
public void test_record_2_constructors_secondCtorUse_withOnlyFieldDecoder() throws IOException {
205+
206+
record TestRecord6(long val) {
207+
208+
@JsonCreator
209+
public TestRecord6(@JsonProperty("valInt") int valInt) {
210+
this(Long.valueOf(valInt));
211+
}
212+
}
213+
214+
JsonIterator iter = JsonIterator.parse("{ 'valInt' : 1 }".replace('\'', '"'));
215+
TestRecord6 record = iter.read(TestRecord6.class);
216+
217+
assertNotNull(record);
218+
}
219+
206220
public void test_record_withCtorDecoder() throws IOException {
207221

208222
record TestRecord2(@JsonProperty long field1) {

0 commit comments

Comments
 (0)