1
1
package com .fasterxml .jackson .dataformat .protobuf .schema ;
2
2
3
3
import java .nio .ByteBuffer ;
4
+ import java .nio .charset .StandardCharsets ;
4
5
import java .util .UUID ;
5
6
7
+ import org .junit .Assert ;
8
+
6
9
import com .fasterxml .jackson .annotation .JsonProperty ;
7
10
import com .fasterxml .jackson .dataformat .protobuf .ProtobufMapper ;
8
11
import com .fasterxml .jackson .dataformat .protobuf .ProtobufTestBase ;
@@ -43,6 +46,17 @@ public void testWithUUID() throws Exception
43
46
{
44
47
ProtobufSchema schema = MAPPER .generateSchemaFor (UUIDBean .class );
45
48
assertNotNull (schema );
49
+
50
+ UUIDBean input = new UUIDBean ();
51
+ input .messageId = UUID .nameUUIDFromBytes ("abc" .getBytes (StandardCharsets .UTF_8 ));
52
+
53
+ byte [] proto = MAPPER .writer ().with (schema )
54
+ .writeValueAsBytes (input );
55
+ UUIDBean result = MAPPER .readerFor (UUIDBean .class )
56
+ .with (schema )
57
+ .readValue (proto );
58
+ assertNotNull (result .messageId );
59
+ assertEquals (input .messageId , result .messageId );
46
60
}
47
61
48
62
// [dataformats-binary#68]
@@ -56,5 +70,17 @@ public void testWithBinary() throws Exception
56
70
{
57
71
ProtobufSchema schema = MAPPER .generateSchemaFor (BinaryBean .class );
58
72
assertNotNull (schema );
73
+
74
+ // But let's try round-tripping too
75
+ BinaryBean input = new BinaryBean ();
76
+ input .data = new byte [] { 1 , 2 , -1 };
77
+
78
+ byte [] proto = MAPPER .writer ().with (schema )
79
+ .writeValueAsBytes (input );
80
+ BinaryBean result = MAPPER .readerFor (BinaryBean .class )
81
+ .with (schema )
82
+ .readValue (proto );
83
+ assertNotNull (result .data );
84
+ Assert .assertArrayEquals (input .data , result .data );
59
85
}
60
86
}
0 commit comments