diff --git a/src/main/java/com/jsoniter/spi/ClassDescriptor.java b/src/main/java/com/jsoniter/spi/ClassDescriptor.java index 98217398..6cf71818 100644 --- a/src/main/java/com/jsoniter/spi/ClassDescriptor.java +++ b/src/main/java/com/jsoniter/spi/ClassDescriptor.java @@ -203,14 +203,13 @@ private static ConstructorDescriptor getCtor(Class clazz) { return cctor; } - private static ConstructorDescriptor getRecordCtor(Class clazz) { + private static ConstructorDescriptor getRecordCtor(Class clazz) { ConstructorDescriptor cctor = new ConstructorDescriptor(); try { - Constructor ctor = clazz.getDeclaredConstructors()[0]; - cctor.ctor = ctor; - for (Type parameter : ctor.getParameterTypes()) { - ClassInfo info = new ClassInfo(parameter); - } + Class[] canonicalParameterTypes = Arrays.stream(clazz.getRecordComponents()).map(RecordComponent::getType).toArray(Class[]::new); + System.out.println("Canonical Parameter Types : "); + System.out.println(Arrays.toString(canonicalParameterTypes)); + cctor.ctor = clazz.getDeclaredConstructor(canonicalParameterTypes); } catch (Exception e) { cctor.ctor = null; } diff --git a/src/test/java/com/jsoniter/TestRecord.java b/src/test/java/com/jsoniter/TestRecord.java index 1dbcc138..3023de30 100644 --- a/src/test/java/com/jsoniter/TestRecord.java +++ b/src/test/java/com/jsoniter/TestRecord.java @@ -5,9 +5,7 @@ import com.jsoniter.annotation.JsonProperty; import com.jsoniter.any.Any; import com.jsoniter.spi.ClassInfo; -import com.jsoniter.spi.EmptyExtension; import com.jsoniter.spi.JsonException; -import com.jsoniter.spi.JsoniterSpi; import junit.framework.TestCase; import java.io.IOException; @@ -103,7 +101,6 @@ public void test_record_error() throws IOException { } } - public void test_record_withOnlyFieldDecoder() throws IOException { assertEquals(ReflectionRecordDecoder.OnlyFieldRecord.class, ReflectionDecoderFactory.create(new ClassInfo(TestRecord1.class)).getClass()); @@ -200,7 +197,7 @@ public TestRecord6(int valInt) { assertEquals(ReflectionRecordDecoder.OnlyFieldRecord.class, ReflectionDecoderFactory.create(new ClassInfo(TestRecord6.class)).getClass()); - JsonIterator iter = JsonIterator.parse("{ 'valInt' : 1 }".replace('\'', '"')); + JsonIterator iter = JsonIterator.parse("{ 'val' : 1 }".replace('\'', '"')); TestRecord6 record = iter.read(TestRecord6.class); assertNotNull(record);