You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@avro.apache.org by "Ryan Skraba (JIRA)" <ji...@apache.org> on 2019/07/09 09:00:00 UTC

[jira] [Commented] (AVRO-2449) Velocity Templates do not allow for Jackson unmarhsalling to JSON

    [ https://issues.apache.org/jira/browse/AVRO-2449?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=16881067#comment-16881067 ] 

Ryan Skraba commented on AVRO-2449:
-----------------------------------

For info, there's been some effort put into removing jackson classes from the public API: AVRO-1605, AVRO-1605

Does generated code count as part of the public API?  It seems to me that it would...  Is there another solution that could help improve the out-of-the-box jackson serialization?  Making these annotations opt-in or configurable, or a velocity extension for annotating methods that do not contain record-specific data?

> 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
>            Priority: Minor
>
> *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)