-
-
Notifications
You must be signed in to change notification settings - Fork 138
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
884769a
commit 02e2ff9
Showing
2 changed files
with
58 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
58 changes: 58 additions & 0 deletions
58
avro/src/test/java/com/fasterxml/jackson/dataformat/avro/failing/POJOEvolution164Test.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
package com.fasterxml.jackson.dataformat.avro.failing; | ||
|
||
import com.fasterxml.jackson.dataformat.avro.AvroMapper; | ||
import com.fasterxml.jackson.dataformat.avro.AvroSchema; | ||
import com.fasterxml.jackson.dataformat.avro.AvroTestBase; | ||
|
||
public class POJOEvolution164Test extends AvroTestBase | ||
{ | ||
static class MyClass { | ||
public String stringField; | ||
public long longField; | ||
} | ||
|
||
private final AvroMapper MAPPER = getMapper(); | ||
|
||
public void testBase() throws Exception | ||
{ | ||
final String WRITER_SCHEMA_SRC = "{\n" + | ||
" \"type\": \"record\",\n" + | ||
" \"name\": \"MyClass\",\n" + | ||
" \"fields\": [\n" + | ||
" { \"name\": \"longField\", \"type\": \"long\"\n },\n" + | ||
" { \"name\": \"stringField\",\n" + | ||
" \"type\": [\n" + | ||
" \"null\",\n" + | ||
" \"string\"\n" + | ||
" ]\n" + | ||
" }\n" + | ||
" ]\n" + | ||
"}"; | ||
final String READER_SCHEMA_SRC = "{\n" + | ||
" \"type\": \"record\",\n" + | ||
" \"name\": \"MyClass\",\n" + | ||
" \"fields\": [\n" + | ||
" {\"name\": \"stringField\",\n" + | ||
" \"type\": [\n" + | ||
" \"null\",\n" + | ||
" \"string\"\n" + | ||
" ]\n" + | ||
" }\n" + | ||
" ]\n" + | ||
"}"; | ||
|
||
final AvroSchema readerSchema = MAPPER.schemaFrom(READER_SCHEMA_SRC); | ||
final AvroSchema writerSchema = MAPPER.schemaFrom(WRITER_SCHEMA_SRC); | ||
|
||
MyClass aClass = new MyClass(); | ||
aClass.stringField = "String value"; | ||
aClass.longField = 42; | ||
byte[] avro = MAPPER.writer() | ||
.with(writerSchema) | ||
.writeValueAsBytes(aClass); | ||
MyClass result = MAPPER.readerFor(MyClass.class) | ||
.with(readerSchema) | ||
.readValue(avro); | ||
assertEquals(aClass.stringField, result.stringField); | ||
} | ||
} |