test: collection of records and compact constructor
diff --git a/src/test/java/org/eclipse/yasson/records/RecordItem.java b/src/test/java/org/eclipse/yasson/records/RecordItem.java new file mode 100644 index 0000000..780c946 --- /dev/null +++ b/src/test/java/org/eclipse/yasson/records/RecordItem.java
@@ -0,0 +1,25 @@ +/* + * Copyright (c) 2026 Contributors to the Eclipse Foundation + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v. 2.0 which is available at + * http://www.eclipse.org/legal/epl-2.0, + * or the Eclipse Distribution License v. 1.0 which is available at + * http://www.eclipse.org/org/documents/edl-v10.php. + * + * SPDX-License-Identifier: EPL-2.0 OR BSD-3-Clause + */ + +package org.eclipse.yasson.records; + +import jakarta.json.bind.annotation.JsonbCreator; + +/** + * Child record used by {@link RecordWithList}. + */ +public record RecordItem(String required, String optional) { + + @JsonbCreator + public RecordItem { + } +}
diff --git a/src/test/java/org/eclipse/yasson/records/RecordTest.java b/src/test/java/org/eclipse/yasson/records/RecordTest.java index 813120d..e8998b4 100644 --- a/src/test/java/org/eclipse/yasson/records/RecordTest.java +++ b/src/test/java/org/eclipse/yasson/records/RecordTest.java
@@ -21,10 +21,13 @@ import org.eclipse.yasson.internal.properties.Messages; import org.junit.jupiter.api.Test; +import java.util.List; import java.util.Set; import static org.hamcrest.MatcherAssert.assertThat; import static org.hamcrest.Matchers.containsString; +import static org.hamcrest.Matchers.hasSize; +import static org.hamcrest.Matchers.instanceOf; import static org.hamcrest.Matchers.is; import static org.hamcrest.Matchers.not; import static org.junit.jupiter.api.Assertions.assertEquals; @@ -237,4 +240,31 @@ RecordWithTypeAdapter record = Jsonbs.defaultJsonb.fromJson(json, RecordWithTypeAdapter.class); assertThat(record.entries(), is(Set.of("a", "b", "c"))); } + + /** + * Regression test for https://github.com/eclipse-ee4j/yasson/issues/656. + * <p> + * A record with a {@code List<RecordType>} component and a compact {@code @JsonbCreator} + * constructor must deserialize list elements as the declared record type, not as + * {@code Map} instances. This was broken on certain JDK 21 builds due to + * JDK bug JDK-8320575 where generic type parameters on compact constructors were + * not resolved correctly by reflection. + */ + @Test + public void testRecordWithListOfRecordsDeserializesElementsAsRecordType() { + String json = "{\"name\":\"parent\",\"items\":[{\"required\":\"a\",\"optional\":\"b\"},{\"required\":\"c\"}]}"; + + RecordWithList result = Jsonbs.defaultJsonb.fromJson(json, RecordWithList.class); + + assertThat(result.name(), is("parent")); + assertThat(result.items(), hasSize(2)); + assertThat("list elements must be RecordItem, not Map", + result.items().get(0), instanceOf(RecordItem.class)); + + assertThat(result.items().get(0).required(), is("a")); + assertThat(result.items().get(0).optional(), is("b")); + + assertThat(result.items().get(1).required(), is("c")); + assertThat(result.items().get(1).optional(), is((String) null)); + } }
diff --git a/src/test/java/org/eclipse/yasson/records/RecordWithList.java b/src/test/java/org/eclipse/yasson/records/RecordWithList.java new file mode 100644 index 0000000..713489b --- /dev/null +++ b/src/test/java/org/eclipse/yasson/records/RecordWithList.java
@@ -0,0 +1,28 @@ +/* + * Copyright (c) 2026 Contributors to the Eclipse Foundation + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v. 2.0 which is available at + * http://www.eclipse.org/legal/epl-2.0, + * or the Eclipse Distribution License v. 1.0 which is available at + * http://www.eclipse.org/org/documents/edl-v10.php. + * + * SPDX-License-Identifier: EPL-2.0 OR BSD-3-Clause + */ + +package org.eclipse.yasson.records; + +import jakarta.json.bind.annotation.JsonbCreator; + +import java.util.List; + +/** + * Reproducer for https://github.com/eclipse-ee4j/yasson/issues/656. + * A record with a {@code List} component and a compact {@code @JsonbCreator} constructor. + */ +public record RecordWithList(String name, List<RecordItem> items) { + + @JsonbCreator + public RecordWithList { + } +}