Skip to content

Commit 24e84e1

Browse files
committed
Merge branch '2.10'
2 parents d65d633 + fc55b4d commit 24e84e1

File tree

2 files changed

+48
-0
lines changed

2 files changed

+48
-0
lines changed

avro/src/test/java/com/fasterxml/jackson/dataformat/avro/AvroTestBase.java

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -282,6 +282,19 @@ protected AvroSchema getStringMapSchema() throws IOException {
282282
return getMapper().schemaFrom(STRING_MAP_SCHEMA_JSON);
283283
}
284284

285+
protected AvroSchema parseSchema(String schemaAsJson) {
286+
return parseSchema(getMapper(), schemaAsJson);
287+
}
288+
289+
protected AvroSchema parseSchema(AvroMapper mapper, String schemaAsJson) {
290+
try {
291+
return getMapper().schemaFrom(aposToQuotes(schemaAsJson));
292+
} catch (IOException e) {
293+
fail("Could not parse Avro Schema from: "+schemaAsJson+", problem: "+e);
294+
return null;
295+
}
296+
}
297+
285298
protected AvroMapper getMapper() {
286299
if (_sharedMapper == null) {
287300
_sharedMapper = newMapper();
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
package com.fasterxml.jackson.dataformat.avro.failing;
2+
3+
import com.fasterxml.jackson.annotation.JsonAutoDetect;
4+
5+
import com.fasterxml.jackson.dataformat.avro.AvroMapper;
6+
import com.fasterxml.jackson.dataformat.avro.AvroSchema;
7+
import com.fasterxml.jackson.dataformat.avro.AvroTestBase;
8+
9+
public class EmptyRecordRead177Test extends AvroTestBase
10+
{
11+
private final AvroMapper MAPPER = getMapper();
12+
13+
private final AvroSchema SCHEMA = parseSchema(MAPPER,
14+
"{'type':'record', 'name':'Empty','namespace':'something','fields':[]}");
15+
16+
@JsonAutoDetect // just a marker to avoid "no properties found" exception
17+
static final class Empty {
18+
@Override
19+
public boolean equals(Object o) {
20+
return o instanceof Empty;
21+
}
22+
}
23+
24+
public void testEmptyRecord() throws Exception {
25+
final Empty empty = new Empty();
26+
27+
byte[] ser = MAPPER.writer().with(SCHEMA).writeValueAsBytes(empty);
28+
29+
final Empty result = MAPPER.readerFor(Empty.class)
30+
.with(SCHEMA)
31+
.readValue(ser);
32+
33+
assertEquals(empty, result);
34+
}
35+
}

0 commit comments

Comments
 (0)