Skip to content

Commit d733d03

Browse files
committed
Minor clean up wrt #324 to align 2.x and 3.0 codebases
1 parent 7a48423 commit d733d03

File tree

2 files changed

+16
-13
lines changed

2 files changed

+16
-13
lines changed

avro/src/main/java/com/fasterxml/jackson/dataformat/avro/schema/AvroSchemaHelper.java

+10-8
Original file line numberDiff line numberDiff line change
@@ -98,9 +98,9 @@ public static boolean isStringable(AnnotatedClass type) {
9898
return false;
9999
}
100100

101-
protected static String getNamespace(BeanDescription bean) {
102-
AvroNamespace ann = bean.getClassInfo().getAnnotation(AvroNamespace.class);
103-
return ann != null ? ann.value() : getNamespace(bean.getType().getRawClass());
101+
protected static String getNamespace(JavaType type, AnnotatedClass annotations) {
102+
AvroNamespace ann = annotations.getAnnotation(AvroNamespace.class);
103+
return ann != null ? ann.value() : getNamespace(type.getRawClass());
104104
}
105105

106106
protected static String getNamespace(Class<?> cls) {
@@ -243,11 +243,12 @@ protected static <T> T throwUnsupported() {
243243
* needs to have fields added to it.
244244
*/
245245
public static Schema initializeRecordSchema(BeanDescription bean) {
246+
final JavaType beanType = bean.getType();
246247
return addAlias(Schema.createRecord(
247-
getName(bean.getType()),
248+
getName(beanType),
248249
bean.findClassDescription(),
249-
getNamespace(bean),
250-
bean.getType().isTypeOrSubTypeOf(Throwable.class)
250+
getNamespace(beanType, bean.getClassInfo()),
251+
beanType.isTypeOrSubTypeOf(Throwable.class)
251252
), bean);
252253
}
253254

@@ -267,10 +268,11 @@ public static Schema parseJsonSchema(String json) {
267268
* @return An {@link org.apache.avro.Schema.Type#ENUM ENUM} schema.
268269
*/
269270
public static Schema createEnumSchema(BeanDescription bean, List<String> values) {
271+
final JavaType enumType = bean.getType();
270272
return addAlias(Schema.createEnum(
271-
getName(bean.getType()),
273+
getName(enumType),
272274
bean.findClassDescription(),
273-
getNamespace(bean), values
275+
getNamespace(enumType, bean.getClassInfo()), values
274276
), bean);
275277
}
276278

avro/src/test/java/com/fasterxml/jackson/dataformat/avro/annotations/AvroNamespaceTest.java

+6-5
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,11 @@
11
package com.fasterxml.jackson.dataformat.avro.annotations;
22

3-
import com.fasterxml.jackson.databind.JsonMappingException;
43
import com.fasterxml.jackson.dataformat.avro.AvroMapper;
54
import com.fasterxml.jackson.dataformat.avro.annotation.AvroNamespace;
65
import com.fasterxml.jackson.dataformat.avro.schema.AvroSchemaGenerator;
6+
77
import org.apache.avro.Schema;
8+
89
import org.junit.Test;
910

1011
import static org.assertj.core.api.Assertions.assertThat;
@@ -24,7 +25,7 @@ enum EnumWithoutAvroNamespaceAnnotation {FOO, BAR;}
2425
enum EnumWithAvroNamespaceAnnotation {FOO, BAR;}
2526

2627
@Test
27-
public void class_without_AvroNamespace_test() throws JsonMappingException {
28+
public void class_without_AvroNamespace_test() throws Exception {
2829
// GIVEN
2930
AvroMapper mapper = new AvroMapper();
3031
AvroSchemaGenerator gen = new AvroSchemaGenerator();
@@ -39,7 +40,7 @@ public void class_without_AvroNamespace_test() throws JsonMappingException {
3940
}
4041

4142
@Test
42-
public void class_with_AvroNamespace_test() throws JsonMappingException {
43+
public void class_with_AvroNamespace_test() throws Exception {
4344
// GIVEN
4445
AvroMapper mapper = new AvroMapper();
4546
AvroSchemaGenerator gen = new AvroSchemaGenerator();
@@ -54,7 +55,7 @@ public void class_with_AvroNamespace_test() throws JsonMappingException {
5455
}
5556

5657
@Test
57-
public void enum_without_AvroNamespace_test() throws JsonMappingException {
58+
public void enum_without_AvroNamespace_test() throws Exception {
5859
// GIVEN
5960
AvroMapper mapper = new AvroMapper();
6061
AvroSchemaGenerator gen = new AvroSchemaGenerator();
@@ -69,7 +70,7 @@ public void enum_without_AvroNamespace_test() throws JsonMappingException {
6970
}
7071

7172
@Test
72-
public void enum_with_AvroNamespace_test() throws JsonMappingException {
73+
public void enum_with_AvroNamespace_test() throws Exception {
7374
// GIVEN
7475
AvroMapper mapper = new AvroMapper();
7576
AvroSchemaGenerator gen = new AvroSchemaGenerator();

0 commit comments

Comments
 (0)