Skip to content

Commit 9e27d43

Browse files
committed
Add test to show issue wrt #483
1 parent d61c086 commit 9e27d43

File tree

2 files changed

+62
-1
lines changed

2 files changed

+62
-1
lines changed
Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
package com.fasterxml.jackson.dataformat.protobuf.schema;
2+
3+
import static org.junit.Assert.assertArrayEquals;
4+
5+
import org.junit.Ignore;
6+
7+
import com.fasterxml.jackson.dataformat.protobuf.ProtobufMapper;
8+
import com.fasterxml.jackson.dataformat.protobuf.ProtobufTestBase;
9+
10+
public class SchemaWithIntArray483Test extends ProtobufTestBase
11+
{
12+
static class IntArrayBean
13+
{
14+
// @JsonProperty(required = true, index = 1)
15+
public int[] value;
16+
}
17+
18+
/*
19+
/**********************************************************
20+
/* Test methods
21+
/**********************************************************
22+
*/
23+
24+
private final ProtobufMapper MAPPER = new ProtobufMapper();
25+
26+
// [dataformats-binary#483]: int arrays supported as nested (property) values
27+
public void testWithWrappedIntArray() throws Exception
28+
{
29+
ProtobufSchema schema = MAPPER.generateSchemaFor(IntArrayBean.class);
30+
assertNotNull(schema);
31+
32+
IntArrayBean input = new IntArrayBean();
33+
input.value = new int[] { 1, 2, 3 };
34+
35+
byte[] proto = MAPPER.writer().with(schema)
36+
.writeValueAsBytes(input);
37+
IntArrayBean result = MAPPER.readerFor(IntArrayBean.class)
38+
.with(schema)
39+
.readValue(proto);
40+
assertNotNull(result.value);
41+
assertArrayEquals(input.value, result.value);
42+
}
43+
44+
// [dataformats-binary#483]: cannot support root-level arrays, unfortunately
45+
@Ignore("Can't be supported with Protobuf")
46+
public void dontTestWithRootIntArray() throws Exception
47+
{
48+
ProtobufSchema schema = MAPPER.generateSchemaFor(int[].class);
49+
assertNotNull(schema);
50+
51+
int[] input = new int[] { 1, 2, 3 };
52+
53+
byte[] proto = MAPPER.writer().with(schema)
54+
.writeValueAsBytes(input);
55+
int[] result = MAPPER.readerFor(int[].class)
56+
.with(schema)
57+
.readValue(proto);
58+
assertNotNull(result);
59+
assertArrayEquals(input, result);
60+
}
61+
}

protobuf/src/test/java/com/fasterxml/jackson/dataformat/protobuf/schema/SchemaWithUUIDTest.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ static class BinaryBean
3939
/**********************************************************
4040
*/
4141

42-
final ProtobufMapper MAPPER = new ProtobufMapper();
42+
private final ProtobufMapper MAPPER = new ProtobufMapper();
4343

4444
// [dataformats-binary#68]
4545
public void testWithUUID() throws Exception

0 commit comments

Comments
 (0)