Skip to content

Commit c896888

Browse files
committed
recreate: #681
1 parent 40c0444 commit c896888

File tree

3 files changed

+46
-1
lines changed

3 files changed

+46
-1
lines changed
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
/*
2+
* Copyright (c) 2025 IBM and/or its affiliates. All rights reserved.
3+
*
4+
* This program and the accompanying materials are made available under the
5+
* terms of the Eclipse Public License v. 2.0 which is available at
6+
* http://www.eclipse.org/legal/epl-2.0,
7+
* or the Eclipse Distribution License v. 1.0 which is available at
8+
* http://www.eclipse.org/org/documents/edl-v10.php.
9+
*
10+
* SPDX-License-Identifier: EPL-2.0 OR BSD-3-Clause
11+
*/
12+
13+
package org.eclipse.yasson.records;
14+
15+
public record CarWithGenerics<T> (String type, T color) {
16+
}
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
/*
2+
* Copyright (c) 2025 IBM and/or its affiliates. All rights reserved.
3+
*
4+
* This program and the accompanying materials are made available under the
5+
* terms of the Eclipse Public License v. 2.0 which is available at
6+
* http://www.eclipse.org/legal/epl-2.0,
7+
* or the Eclipse Distribution License v. 1.0 which is available at
8+
* http://www.eclipse.org/org/documents/edl-v10.php.
9+
*
10+
* SPDX-License-Identifier: EPL-2.0 OR BSD-3-Clause
11+
*/
12+
13+
package org.eclipse.yasson.records;
14+
15+
public record Color(String name, String code) {
16+
}

src/test/java/org/eclipse/yasson/records/RecordTest.java

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2021, 2024 Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 2021, 2025 Oracle and/or its affiliates. All rights reserved.
33
*
44
* This program and the accompanying materials are made available under the
55
* terms of the Eclipse Public License v. 2.0 which is available at
@@ -15,6 +15,7 @@
1515
import jakarta.json.bind.JsonbException;
1616

1717
import org.eclipse.yasson.Jsonbs;
18+
import org.eclipse.yasson.TestTypeToken;
1819
import org.eclipse.yasson.internal.properties.MessageKeys;
1920
import org.eclipse.yasson.internal.properties.Messages;
2021
import org.junit.jupiter.api.Test;
@@ -106,4 +107,16 @@ public void testRecordWithDefaultConstructor() {
106107
assertThrows(JsonbException.class, () -> Jsonbs.defaultJsonb.fromJson(expected, CarWithDefaultConstructor.class));
107108
}
108109

110+
@Test
111+
public void testRecordWithGenerics() {
112+
CarWithGenerics<Color> car = new CarWithGenerics<>("skoda", new Color("green", "#00FF00"));
113+
String expected = "{\"color\":{\"code\":\"#00FF00\",\"name\":\"green\"},\"type\":\"skoda\"}";
114+
115+
String json = Jsonbs.defaultJsonb.toJson(car);
116+
assertThat(json, is(expected));
117+
118+
CarWithGenerics<Color> deserialized = Jsonbs.defaultJsonb
119+
.fromJson(expected, new TestTypeToken<CarWithGenerics<Color>>() {}.getType());
120+
assertThat(deserialized, is(car));
121+
}
109122
}

0 commit comments

Comments
 (0)