Jeff created AVRO-2449:
--------------------------
Summary: Velocity Templates do not allow for Jackson unmarhsalling
to JSON
Key: AVRO-2449
URL: https://issues.apache.org/jira/browse/AVRO-2449
Project: Apache Avro
Issue Type: Improvement
Components: java
Affects Versions: 1.9.0
Reporter: Jeff
*This applies to working in Kotlin* _Havent tested in java_
When using java classes auto-generated by the Avro-tools or the Gradle tasks
(in my case) the output classes are not out of the box compatible with
serializing to JSON.
I detailed my issues in this stack post:
[https://stackoverflow.com/questions/56742226/avro-generated-class-issue-with-json-conversion-kotlin]
Specifically it appears that the two calls:
{code:java}
public org.apache.avro.specific.SpecificData getSpecificData() { return MODEL$;
}
public org.apache.avro.Schema getSchema() { return SCHEMA$; }
{code}
Are at issue - when I attempt to convert one of these records into Json using
ObjectMapper.
So there are two approaches I've come up with:
1) To create a Mixin for Jackson:
{code:java}
abstract class AvroMixIn {
@JsonIgnore
abstract fun getSchema(): org.apache.avro.Schema
@JsonIgnore
abstract fun getSpecificData() : org.apache.avro.specific.SpecificData
}{code}
And then I can apply this to the objet mapper (in a lazy way to all objects)
{code:java}
// Register the global object mapper to use the java time module (i think this
is done elsewhere already) and to use the mixin to make it easy to jackson
decode Avro stuff
objectMapper
.registerModule(JavaTimeModule())
.addMixIn(Object::class.java, AvroMixIn::class.java)
{code}
The alternative would be to modify the velocity templates (which I also did) to
add a
{code:java}
@com.fasterxml.jackson.annotation.JsonIgnore
{code}
annotation in front of the *getSpecificData* and *getSchema* calls
As I'm pretty sure Jackson is a dependency of this project I'm wondering if its
a reasonable consideration to modify the templates to add the *@JsonIgnore*
annotation to make it easy to serailize/unserialze data right out of the box.
--
This message was sent by Atlassian JIRA
(v7.6.3#76005)