diff --git a/protobuf/src/main/java/com/fasterxml/jackson/dataformat/protobuf/schemagen/ProtobufSchemaHelper.java b/protobuf/src/main/java/com/fasterxml/jackson/dataformat/protobuf/schemagen/ProtobufSchemaHelper.java index f143034e0..7a43f0c60 100644 --- a/protobuf/src/main/java/com/fasterxml/jackson/dataformat/protobuf/schemagen/ProtobufSchemaHelper.java +++ b/protobuf/src/main/java/com/fasterxml/jackson/dataformat/protobuf/schemagen/ProtobufSchemaHelper.java @@ -1,6 +1,7 @@ package com.fasterxml.jackson.dataformat.protobuf.schemagen; import java.nio.ByteBuffer; +import java.util.UUID; import com.fasterxml.jackson.databind.*; @@ -55,6 +56,8 @@ public static boolean hasIndex(BeanProperty writer) { public static boolean isBinaryType(JavaType type) { return type.hasRawClass(byte[].class) + // 24-Jul-2024, tatu: [dataformats-binary#506] UUID as Binary + || type.hasRawClass(UUID.class) || type.isTypeOrSubTypeOf(ByteBuffer.class); } } diff --git a/protobuf/src/test/java/com/fasterxml/jackson/dataformat/protobuf/schema/SchemaWithUUIDTest.java b/protobuf/src/test/java/com/fasterxml/jackson/dataformat/protobuf/schema/SchemaWithUUIDTest.java index 7b343d43b..b547e17bc 100644 --- a/protobuf/src/test/java/com/fasterxml/jackson/dataformat/protobuf/schema/SchemaWithUUIDTest.java +++ b/protobuf/src/test/java/com/fasterxml/jackson/dataformat/protobuf/schema/SchemaWithUUIDTest.java @@ -1,8 +1,11 @@ package com.fasterxml.jackson.dataformat.protobuf.schema; import java.nio.ByteBuffer; +import java.nio.charset.StandardCharsets; import java.util.UUID; +import org.junit.Assert; + import com.fasterxml.jackson.annotation.JsonProperty; import com.fasterxml.jackson.dataformat.protobuf.ProtobufMapper; import com.fasterxml.jackson.dataformat.protobuf.ProtobufTestBase; @@ -43,6 +46,17 @@ public void testWithUUID() throws Exception { ProtobufSchema schema = MAPPER.generateSchemaFor(UUIDBean.class); assertNotNull(schema); + + UUIDBean input = new UUIDBean(); + input.messageId = UUID.nameUUIDFromBytes("abc".getBytes(StandardCharsets.UTF_8)); + + byte[] proto = MAPPER.writer().with(schema) + .writeValueAsBytes(input); + UUIDBean result = MAPPER.readerFor(UUIDBean.class) + .with(schema) + .readValue(proto); + assertNotNull(result.messageId); + assertEquals(input.messageId, result.messageId); } // [dataformats-binary#68] @@ -56,5 +70,17 @@ public void testWithBinary() throws Exception { ProtobufSchema schema = MAPPER.generateSchemaFor(BinaryBean.class); assertNotNull(schema); + + // But let's try round-tripping too + BinaryBean input = new BinaryBean(); + input.data = new byte[] { 1, 2, -1 }; + + byte[] proto = MAPPER.writer().with(schema) + .writeValueAsBytes(input); + BinaryBean result = MAPPER.readerFor(BinaryBean.class) + .with(schema) + .readValue(proto); + assertNotNull(result.data); + Assert.assertArrayEquals(input.data, result.data); } } diff --git a/release-notes/VERSION-2.x b/release-notes/VERSION-2.x index 69093e362..878161774 100644 --- a/release-notes/VERSION-2.x +++ b/release-notes/VERSION-2.x @@ -18,6 +18,11 @@ Active maintainers: - No changes since 2.17 +2.17.3 (not yet released) + +#506: Cannot deserialize `UUID` values + (reported by @uniquonil) + 2.17.2 (05-Jul-2024) #497: (ion) Failed copy(): `IonValueMapper` does not override copy()