Skip to content

Commit 578d3ab

Browse files
committed
Minor work related to #179, but can't fix for 2.10
1 parent 09c18b1 commit 578d3ab

File tree

3 files changed

+55
-6
lines changed

3 files changed

+55
-6
lines changed

avro/src/main/java/com/fasterxml/jackson/dataformat/avro/AvroFactory.java

+6-1
Original file line numberDiff line numberDiff line change
@@ -167,7 +167,12 @@ public AvroFactory copy()
167167
public boolean requiresPropertyOrdering() {
168168
return true;
169169
}
170-
170+
171+
@Override // since 2.10 (should have been earlier)
172+
public boolean canHandleBinaryNatively() {
173+
return true;
174+
}
175+
171176
/*
172177
/**********************************************************
173178
/* Serializable overrides

avro/src/main/java/com/fasterxml/jackson/dataformat/avro/AvroGenerator.java

+16-5
Original file line numberDiff line numberDiff line change
@@ -205,11 +205,6 @@ public int getOutputBuffered() {
205205
return -1;
206206
}
207207

208-
@Override
209-
public boolean canUseSchema(FormatSchema schema) {
210-
return (schema instanceof AvroSchema);
211-
}
212-
213208
@Override public AvroSchema getSchema() {
214209
return _rootSchema;
215210
}
@@ -224,6 +219,22 @@ public void setSchema(FormatSchema schema)
224219
setSchema((AvroSchema) schema);
225220
}
226221

222+
/*
223+
/**********************************************************
224+
/* Public API, capability introspection methods
225+
/**********************************************************
226+
*/
227+
228+
@Override
229+
public boolean canUseSchema(FormatSchema schema) {
230+
return (schema instanceof AvroSchema);
231+
}
232+
233+
// 10-Sep-2019, Tatu: Should implement wrt [dataformats-binary#179], but...
234+
// can't. Not yet, will just break things. Wait until 2.11
235+
// @Override
236+
// public boolean canWriteBinaryNatively() { return true; }
237+
227238
/*
228239
/**********************************************************
229240
/* Extended API, configuration
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
package com.fasterxml.jackson.dataformat.avro;
2+
3+
import java.util.UUID;
4+
5+
// @since 2.10
6+
public class UUIDTest extends AvroTestBase
7+
{
8+
static class UUIDWrapper {
9+
public UUID id;
10+
11+
protected UUIDWrapper() { }
12+
public UUIDWrapper(UUID u) { id = u; }
13+
}
14+
15+
private final AvroMapper MAPPER = newMapper();
16+
17+
// 10-Sep-2019, tatu: as per [dataformats-binary#179], should really serialize
18+
// UUID as binary, but due to various complications can not make it work
19+
// safely and reliably with 2.10; can only add some foundational support.
20+
public void testUUIDRoundtrip() throws Exception
21+
{
22+
final AvroSchema schema = MAPPER.schemaFor(UUIDWrapper.class);
23+
//System.err.println("DEBUG: schema -> "+schema.getAvroSchema());
24+
UUIDWrapper input = new UUIDWrapper(UUID.nameUUIDFromBytes("BOGUS".getBytes("UTF-8")));
25+
byte[] avro = MAPPER.writer(schema).writeValueAsBytes(input);
26+
27+
UUIDWrapper output = MAPPER.readerFor(UUIDWrapper.class)
28+
.with(schema)
29+
.readValue(avro);
30+
31+
assertEquals(input.id, output.id);
32+
}
33+
}

0 commit comments

Comments
 (0)