test: JsonbTypeDeserialzier on record Co-authored-by-AI: IBM Bob (1.126.0+bob2.2.2)
diff --git a/src/test/java/org/eclipse/yasson/records/RecordTest.java b/src/test/java/org/eclipse/yasson/records/RecordTest.java index bf3ad00..46cd64f 100644 --- a/src/test/java/org/eclipse/yasson/records/RecordTest.java +++ b/src/test/java/org/eclipse/yasson/records/RecordTest.java
@@ -28,6 +28,7 @@ import java.time.LocalDate; import java.util.List; import java.util.Set; +import java.util.UUID; import static org.hamcrest.MatcherAssert.assertThat; import static org.hamcrest.Matchers.containsString; @@ -232,6 +233,23 @@ } // ----------------------------------------------------------------- + // Issue #606 — @JsonbTypeDeserializer on record components + // ----------------------------------------------------------------- + + /** + * Regression test for https://github.com/eclipse-ee4j/yasson/issues/606. + * <p> + * Deserialising into a record whose component is annotated with {@code @JsonbTypeDeserializer} + * must invoke the custom deserializer rather than the default deserializer. + */ + @Test + public void testRecordWithTypeDeserializer() { + String json = "{\"sys_id\":\"2b8f1a676f04c7c027e0cc60cb1f4ec3\"}"; + RecordWithTypeDeserializer record = Jsonbs.defaultJsonb.fromJson(json, RecordWithTypeDeserializer.class); + assertThat(record.sysId(), is(UUID.fromString("2b8f1a67-6f04-c7c0-27e0-cc60cb1f4ec3"))); + } + + // ----------------------------------------------------------------- // Issue #607 — @JsonbTypeAdapter on record components // -----------------------------------------------------------------
diff --git a/src/test/java/org/eclipse/yasson/records/RecordWithTypeDeserializer.java b/src/test/java/org/eclipse/yasson/records/RecordWithTypeDeserializer.java new file mode 100644 index 0000000..c4685a5 --- /dev/null +++ b/src/test/java/org/eclipse/yasson/records/RecordWithTypeDeserializer.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.JsonbProperty; +import jakarta.json.bind.annotation.JsonbTypeDeserializer; + +import java.util.UUID; + +/** + * Reproducer record for issue #606: {@code @JsonbTypeDeserializer} annotated on a record component + * must be recognised and applied during deserialisation. + */ +public record RecordWithTypeDeserializer( + @JsonbProperty("sys_id") + @JsonbTypeDeserializer(SysIdDeserializer.class) + UUID sysId) { +}
diff --git a/src/test/java/org/eclipse/yasson/records/SysIdDeserializer.java b/src/test/java/org/eclipse/yasson/records/SysIdDeserializer.java new file mode 100644 index 0000000..dc69d30 --- /dev/null +++ b/src/test/java/org/eclipse/yasson/records/SysIdDeserializer.java
@@ -0,0 +1,38 @@ +/* + * 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.serializer.DeserializationContext; +import jakarta.json.bind.serializer.JsonbDeserializer; +import jakarta.json.stream.JsonParser; + +import java.lang.reflect.Type; +import java.util.UUID; + +/** + * Deserializer used to reproduce issue #606: {@code @JsonbTypeDeserializer} on a record component + * must be recognised and invoked during deserialisation. + * + * Converts a 32-character hex UUID string without hyphens into a {@link UUID}. + */ +public class SysIdDeserializer implements JsonbDeserializer<UUID> { + + @Override + public UUID deserialize(JsonParser parser, DeserializationContext ctx, Type rtType) { + String value = parser.getString(); + if (value.length() == 32) { + value = value.replaceFirst("(\\p{XDigit}{8})(\\p{XDigit}{4})(\\p{XDigit}{4})(\\p{XDigit}{4})(\\p{XDigit}+)", "$1-$2-$3-$4-$5"); + } + return UUID.fromString(value); + } +}