Skip to content
Closed
Changes from 1 commit
Commits
File filter

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
test - example of use of another constructor for record decoding (#16)
  • Loading branch information
mxyns committed Mar 6, 2022
commit 8dc32ff7e1be47821c0384619f35bee0728331cb
22 changes: 18 additions & 4 deletions src/test/java/com/jsoniter/TestRecord.java
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,8 @@
import junit.framework.TestCase;

import java.io.IOException;
import java.lang.reflect.Constructor;
import java.lang.reflect.Field;
import java.lang.reflect.Method;
import java.lang.reflect.Modifier;
import java.lang.reflect.*;
import java.util.Arrays;
import java.util.Map;

public class TestRecord extends TestCase {
Expand Down Expand Up @@ -203,6 +201,22 @@ public TestRecord6(int valInt) {
assertNotNull(record);
}

public void test_record_2_constructors_secondCtorUse_withOnlyFieldDecoder() throws IOException {

record TestRecord6(long val) {

@JsonCreator
public TestRecord6(@JsonProperty("valInt") int valInt) {
this(Long.valueOf(valInt));
}
}

JsonIterator iter = JsonIterator.parse("{ 'valInt' : 1 }".replace('\'', '"'));
TestRecord6 record = iter.read(TestRecord6.class);

assertNotNull(record);
}

public void test_record_withCtorDecoder() throws IOException {

record TestRecord2(@JsonProperty long field1) {
Expand Down