Skip to content

Commit c778631

Browse files
committed
Merge branch '2.8'
2 parents 7fed8c2 + 0a870e1 commit c778631

File tree

1 file changed

+50
-0
lines changed

1 file changed

+50
-0
lines changed
Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
package com.fasterxml.jackson.dataformat.protobuf.failing;
2+
3+
import com.fasterxml.jackson.annotation.JsonPropertyOrder;
4+
5+
import com.fasterxml.jackson.dataformat.protobuf.*;
6+
import com.fasterxml.jackson.dataformat.protobuf.schema.ProtobufSchema;
7+
8+
public class WriteLongString94Test extends ProtobufTestBase
9+
{
10+
@JsonPropertyOrder({ "a", "b" })
11+
public static class TwoStrings {
12+
public String a;
13+
public String b;
14+
}
15+
16+
/*
17+
/**********************************************************
18+
/* Test methods
19+
/**********************************************************
20+
*/
21+
22+
final ProtobufMapper MAPPER = new ProtobufMapper();
23+
24+
// [dataformats-binary#94]
25+
public void testLongerStrings() throws Exception {
26+
TwoStrings p = new TwoStrings();
27+
// near 8000, so index out of bounds at 8000
28+
p.a = makeString(7995);
29+
p.b = makeString(7995);
30+
31+
ProtobufSchema schema = MAPPER.generateSchemaFor(p.getClass());
32+
byte[] proto = MAPPER.writer(schema)
33+
.writeValueAsBytes(p);
34+
assertEquals(13, proto.length);
35+
36+
TwoStrings result = MAPPER.readerFor(p.getClass())
37+
.with(schema)
38+
.readValue(proto);
39+
assertEquals(p.a, result.a);
40+
assertEquals(p.b, result.b);
41+
}
42+
43+
private String makeString(int len) {
44+
StringBuilder sb = new StringBuilder(len);
45+
for (int i = 0; i < len; i++) {
46+
sb.append((char) ('a' + (i & 15)));
47+
}
48+
return sb.toString();
49+
}
50+
}

0 commit comments

Comments
 (0)