This is an enhancement request for dealing with unions types in Java generated POJOs.
If a schema has a union field, then the generated field type in Java is Object. This makes sense since Java doesn't support unions. However, this means that code using the generated POJOs need to do type checking (instanceof) and casting to get the underlying type. A common way to deal with this is the Visitor pattern. There are several articles on this, here's just one I came across via a quick google search - https://dzone.com/articles/design-patterns-visitor. This enhancement request is to code-generate methods that facilitate this pattern. Below [1] I have a rough sketch of what I think it could look like. I'd appreciate your feedback. I'm also willing to contribute if needed. Please let me know; Thanks! [1] https://github.com/commercehub-oss/gradle-avro-plugin/issues/59 p.s. - I first submitted this as a request to the gradle-plugin project in GitHub (link above). Since the formatting is better there, I just point to there as opposed to pasting it here.
