Skip to content

Commit 1ea012f

Browse files
committed
Merge branch '2.8'
2 parents b890ff9 + ec78b04 commit 1ea012f

File tree

1 file changed

+52
-0
lines changed

1 file changed

+52
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
package com.fasterxml.jackson.dataformat.avro;
2+
3+
import com.fasterxml.jackson.dataformat.avro.AvroMapper;
4+
import com.fasterxml.jackson.dataformat.avro.AvroSchema;
5+
6+
/* 23-Aug-2017, tatu: There was some confusion on whether potential ambiguity
7+
* might be problematic (compared to actual one) -- this test verifies
8+
* it should not be.
9+
*/
10+
public class AmbiguousUnionWriteTest extends AvroTestBase
11+
{
12+
protected final String SCHEMA_WITH_AMBIGUITY = aposToQuotes("{\n"
13+
+"'type': 'record',\n"
14+
+"'name': 'WithUnion',\n"
15+
+"'fields': [\n"
16+
+" {'name': 'value', 'type': [ 'string'\n"
17+
+" ,{ 'type' : 'record', 'name' : 'recordA',\n"
18+
+ "'fields' : [ { 'name' : 'extra', 'type' : 'string' } ] }"
19+
+" ,{ 'type' : 'record', 'name' : 'recordB', \n"
20+
+ "'fields' : [ { 'name' : 'x', 'type' : 'int' } ] }"
21+
+" ]\n"
22+
+" }\n"
23+
+"]}"
24+
);
25+
26+
static class StringWrapper {
27+
public String value;
28+
29+
public StringWrapper(String v) { value = v; }
30+
protected StringWrapper() { }
31+
}
32+
33+
/*
34+
/**********************************************************
35+
/* Test methods
36+
/**********************************************************
37+
*/
38+
39+
private final AvroMapper MAPPER = newMapper();
40+
41+
public void testWriteNoAmbiguity() throws Exception
42+
{
43+
AvroSchema schema = MAPPER.schemaFrom(SCHEMA_WITH_AMBIGUITY);
44+
byte[] b = MAPPER.writerFor(StringWrapper.class)
45+
.with(schema)
46+
.writeValueAsBytes(new StringWrapper("foobar"));
47+
StringWrapper output = MAPPER.readerFor(StringWrapper.class)
48+
.with(schema)
49+
.readValue(b);
50+
assertEquals("foobar", output.value);
51+
}
52+
}

0 commit comments

Comments
 (0)