Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Avro Serialization #312

Closed
bkenned4 opened this issue Apr 29, 2016 · 3 comments
Closed

Avro Serialization #312

bkenned4 opened this issue Apr 29, 2016 · 3 comments

Comments

@bkenned4
Copy link

Hey everyone,

The existing serialization support is immutables is great. Any chance Avro is on the radar?

Using immutables with avro is already pretty close to working; however, if one is to change the schema/datamodel, the existing framework falls a bit short.

Consider the case where a new field is added to a datamodel, and with that new datamodel, you want to deserialize older data. Avro can handle this, as long as you have a default value for this new field. it can either be set as @nullable or @AvroDefault("foo")

class OldPersonDatamodel {
   String firstName;
}
class NewPersonDatamodel {
   String firstName;
   @AvroDefault("foo") String lastName;
}

The breakdown is that the collection of annotations are required to be on the field level.

org.apache.avro.reflect
.
.
.
@Retention(RetentionPolicy.RUNTIME)
@Target({ElementType.FIELD})
public @interface AvroDefault {

I'm sure there are other gotchas that crop up, but this was the first one I ran into, since schema evolution is a hard requirement for our usage of Avro.

Thanks,
Brad

@elucash
Copy link
Member

elucash commented Apr 29, 2016

Thank you for the feature request. Currently Avro is not on a radar, but we might have something if we can find a volunteer to contribute a solution. The solution might put Avro annotations for generated fields.
Currently Immutables supports native java serialization, JSON and other binary serialization mechanisms are best supported by plugging in Jackson, like using CBOR, BSON or Smile. We had a similar problem with Gson, where they had field annotation @SerializedName, but recently they switched to support methods also.
Also upcoming 2.2.beta version will allow having Nullable and Value.Default (or is it already supported?) on a attribute so you might get something without field annotation, but I do not have understanding how Avro works or how we can hook Immutables to work with it. Suggestions and contributions are welcome!

@bkenned4
Copy link
Author

bkenned4 commented Apr 29, 2016

Thanks for the response. One potential approach would be to have an annotation to specify what the fields should be annotated with.

@FieldAnnotation(annoation=AvroDefault.class, value="foo")

Definitely would be nice if the Avro followed Gson's lead and supported methods as well

@bkenned4
Copy link
Author

InjectAnnotation gives the flexibility required to support Avro annotations, and thus schema evolution. So I don't see a need for explicit Avro support

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants