Skip to content

Commit e2ef346

Browse files
committed
backport test
1 parent f96cc9a commit e2ef346

File tree

1 file changed

+58
-0
lines changed

1 file changed

+58
-0
lines changed
Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
package com.fasterxml.jackson.dataformat.avro.failing;
2+
3+
import com.fasterxml.jackson.dataformat.avro.AvroMapper;
4+
import com.fasterxml.jackson.dataformat.avro.AvroSchema;
5+
import com.fasterxml.jackson.dataformat.avro.AvroTestBase;
6+
7+
public class POJOEvolution164Test extends AvroTestBase
8+
{
9+
static class MyClass {
10+
public String stringField;
11+
public long longField;
12+
}
13+
14+
private final AvroMapper MAPPER = getMapper();
15+
16+
public void testBase() throws Exception
17+
{
18+
final String WRITER_SCHEMA_SRC = "{\n" +
19+
" \"type\": \"record\",\n" +
20+
" \"name\": \"MyClass\",\n" +
21+
" \"fields\": [\n" +
22+
" { \"name\": \"longField\", \"type\": \"long\"\n },\n" +
23+
" { \"name\": \"stringField\",\n" +
24+
" \"type\": [\n" +
25+
" \"null\",\n" +
26+
" \"string\"\n" +
27+
" ]\n" +
28+
" }\n" +
29+
" ]\n" +
30+
"}";
31+
final String READER_SCHEMA_SRC = "{\n" +
32+
" \"type\": \"record\",\n" +
33+
" \"name\": \"MyClass\",\n" +
34+
" \"fields\": [\n" +
35+
" {\"name\": \"stringField\",\n" +
36+
" \"type\": [\n" +
37+
" \"null\",\n" +
38+
" \"string\"\n" +
39+
" ]\n" +
40+
" }\n" +
41+
" ]\n" +
42+
"}";
43+
44+
final AvroSchema readerSchema = MAPPER.schemaFrom(READER_SCHEMA_SRC);
45+
final AvroSchema writerSchema = MAPPER.schemaFrom(WRITER_SCHEMA_SRC);
46+
47+
MyClass aClass = new MyClass();
48+
aClass.stringField = "String value";
49+
aClass.longField = 42;
50+
byte[] avro = MAPPER.writer()
51+
.with(writerSchema)
52+
.writeValueAsBytes(aClass);
53+
MyClass result = MAPPER.readerFor(MyClass.class)
54+
.with(readerSchema)
55+
.readValue(avro);
56+
assertEquals(aClass.stringField, result.stringField);
57+
}
58+
}

0 commit comments

Comments
 (0)