Skip to content

Commit

Permalink
Add failing test for #164
Browse files Browse the repository at this point in the history
  • Loading branch information
cowtowncoder committed Jun 6, 2019
1 parent 884769a commit 02e2ff9
Show file tree
Hide file tree
Showing 2 changed files with 58 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,6 @@ public static AvroMapper.Builder xmlBuilder() {
/**
* @since 2.10
*/
@SuppressWarnings("unchecked")
public static AvroMapper.Builder builder() {
return new AvroMapper.Builder(new AvroMapper());
}
Expand Down
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);
}
}

0 comments on commit 02e2ff9

Please # to comment.