|
1 | 1 | /* |
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. |
3 | 3 | * |
4 | 4 | * This program and the accompanying materials are made available under the |
5 | 5 | * terms of the Eclipse Public License v. 2.0 which is available at |
|
15 | 15 | import jakarta.json.bind.JsonbException; |
16 | 16 |
|
17 | 17 | import org.eclipse.yasson.Jsonbs; |
| 18 | +import org.eclipse.yasson.TestTypeToken; |
18 | 19 | import org.eclipse.yasson.internal.properties.MessageKeys; |
19 | 20 | import org.eclipse.yasson.internal.properties.Messages; |
20 | 21 | import org.junit.jupiter.api.Test; |
@@ -106,4 +107,16 @@ public void testRecordWithDefaultConstructor() { |
106 | 107 | assertThrows(JsonbException.class, () -> Jsonbs.defaultJsonb.fromJson(expected, CarWithDefaultConstructor.class)); |
107 | 108 | } |
108 | 109 |
|
| 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 | + } |
109 | 122 | } |
0 commit comments