ex-ratt commented on PR #2887:
URL: https://github.com/apache/avro/pull/2887#issuecomment-2112901411

   Sorry for barging into the discussion uninvited, but I am following this PR, 
since I like the idea of such an annotation. If I understood the comments on 
the original issue correctly, then the annotation should not only allow to 
specify the namespace, but also the name of a record/enum - hence the name 
`@AvroTypeName` for the annotation instead of `@AvroNamespace`. The following 
suggestions are from Oscar's comment on the issue, I just adjusted the name of 
the annotation:
   
   1. `@AvroTypeName("simpleOrFullName")` for a named type would set its name, 
optionally with namespace
   2. `@AvroTypeName(value="simpleName", namespace="my.space")` for a named 
type would set its name and namespace
   3. `@AvroTypeName(namespace="my.space")` for a named type would set only the 
namespace and let the name be inferred
   
   I guess this is what @opwvhk is referring to.
   
   On a related note: I really like the idea of this kind of annotation, 
because namespace & name of a record schema can be independent from package & 
name of the corresponding class. However, it does not end there: `ReflectData` 
and `ReflectDatumReader` are not able to deserialize data when the schema of a 
record/enum has a changed name or namespace. Currently, it assumes that the 
class can be inferred from namespace & name of a record, see 
`SpecificData.getClass(Schema)`, which is used by 
`SpecificData.newRecord(Object, Schema)` (and `ReflectData` derives from 
`SpecificData`). I stumbled upon this issue this week when trying to implement 
an `@AvroNamespace` annotation myself.
   
   What solved this issue for me was to add a property to the generated schema 
(`SpecificData.CLASS_PROP`, which is already used to specify classes for Avro 
arrays) and override `ReflectData.getClass(Schema)` to read this property (and 
cache the loaded class, just like `ReflectData.getClassProp(Schema,String)`).
   
   I would appreciate an official solution, so I can throw away my code which 
may break with new versions of the Avro library. 


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to