FasterXML / jackson-dataformats-binary

Uber-project for standard Jackson binary format backends: avro, cbor, ion, protobuf, smile
Apache License 2.0
315 stars 136 forks source link

Support for Avro 'single-object encoding' headers in serialize/deserialize #172

Open salt-tony opened 5 years ago

salt-tony commented 5 years ago

Looking for some inter-operability between the org.apache.avro.message.BinaryMessageEncoder (that is used by the Java beans generated by the avro maven/gradle plug-ins) and the raw bytes generated by the Jackson 'AvroMapper' as per the example code:

byte[] avroData = mapper.writer(schema)
   .writeValueAsBytes(empl);

It looks like the Avro BinaryMessageEncoder is adding a header as described by https://avro.apache.org/docs/1.8.2/spec.html#single_object_encoding_spec

Is there some way to get the Jackson 'AvroMapper' to generate and to parse byte arrays with the same headers?

cowtowncoder commented 5 years ago

I wasn't even aware of the addition to spec. Earlier the only marker was to be used if storing Avro content into a File (or reading from), which was very odd distinction for format to make (I'd much prefer consistent use, regardless of whether streaming over network or storing, which most formats do).

But I think it would be reasonable to support this as a feature. Unfortunately it seems impossible to use reliable auto-detection for signature.

As to existing functionality, theoretically it might be possible to use Decorator approach to wrap/unwrap content. But that would not be very convenient without support from format module.