opwvhk commented on code in PR #2887: URL: https://github.com/apache/avro/pull/2887#discussion_r1587050639
########## lang/java/avro/src/main/java/org/apache/avro/reflect/AvroTypeName.java: ########## @@ -0,0 +1,33 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.apache.avro.reflect; + +import java.lang.annotation.ElementType; +import java.lang.annotation.Retention; +import java.lang.annotation.RetentionPolicy; +import java.lang.annotation.Target; + +/** + * Sets the avrotypename for this java type. When reading into this class, a + * reflectdatumreader looks for a schema field with the avrotypename. + */ +@Retention(RetentionPolicy.RUNTIME) +@Target({ ElementType.TYPE }) +public @interface AvroTypeName { + String value() default ""; Review Comment: Do we always want to specify the name here, or also allow to override the namespace only? ########## lang/java/avro/src/main/java/org/apache/avro/reflect/ReflectData.java: ########## @@ -706,9 +706,7 @@ protected Schema createSchema(Type type, Map<String, Schema> names) { AvroDoc annotatedDoc = c.getAnnotation(AvroDoc.class); // Docstring String doc = (annotatedDoc != null) ? annotatedDoc.value() : null; String name = c.getSimpleName(); - String space = c.getPackage() == null ? "" : c.getPackage().getName(); - if (c.getEnclosingClass() != null) // nested class - space = c.getEnclosingClass().getName().replace('$', '.'); + String space = getNamespace(c); Review Comment: Would the annotation @AvroTypeName not specify the type name? ########## lang/java/avro/src/main/java/org/apache/avro/reflect/ReflectData.java: ########## @@ -802,6 +800,21 @@ private String simpleName(Class<?> c) { return simpleName; } + /* + * Function checks if there is @AvroTypeName annotation on the class. If present + * then returns the value of the annotation else returns the package of the + * class + */ + private String getNamespace(Class<?> c) { + AvroTypeName avroTypeName = c.getAnnotation(AvroTypeName.class); + if (avroTypeName != null) { + return avroTypeName.value(); + } + if (c.getEnclosingClass() != null) // nested class + return c.getEnclosingClass().getName().replace('$', '.'); Review Comment: What if the enclosing class has an @AvroTypeName? -- 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]
