Skip to content

Fix #506: support UUID values with Protobuf #507

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Jul 25, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package com.fasterxml.jackson.dataformat.protobuf.schemagen;

import java.nio.ByteBuffer;
import java.util.UUID;

import com.fasterxml.jackson.databind.*;

Expand Down Expand Up @@ -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);
}
}
Original file line number Diff line number Diff line change
@@ -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;
Expand Down Expand Up @@ -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]
Expand All @@ -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);
}
}
5 changes: 5 additions & 0 deletions release-notes/VERSION-2.x
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down