Skip to content

Commit

Permalink
Minor clean up wrt #324 to align 2.x and 3.0 codebases
Browse files Browse the repository at this point in the history
  • Loading branch information
cowtowncoder committed May 15, 2022
1 parent 7a48423 commit d733d03
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -98,9 +98,9 @@ public static boolean isStringable(AnnotatedClass type) {
return false;
}

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

protected static String getNamespace(Class<?> cls) {
Expand Down Expand Up @@ -243,11 +243,12 @@ protected static <T> T throwUnsupported() {
* needs to have fields added to it.
*/
public static Schema initializeRecordSchema(BeanDescription bean) {
final JavaType beanType = bean.getType();
return addAlias(Schema.createRecord(
getName(bean.getType()),
getName(beanType),
bean.findClassDescription(),
getNamespace(bean),
bean.getType().isTypeOrSubTypeOf(Throwable.class)
getNamespace(beanType, bean.getClassInfo()),
beanType.isTypeOrSubTypeOf(Throwable.class)
), bean);
}

Expand All @@ -267,10 +268,11 @@ public static Schema parseJsonSchema(String json) {
* @return An {@link org.apache.avro.Schema.Type#ENUM ENUM} schema.
*/
public static Schema createEnumSchema(BeanDescription bean, List<String> values) {
final JavaType enumType = bean.getType();
return addAlias(Schema.createEnum(
getName(bean.getType()),
getName(enumType),
bean.findClassDescription(),
getNamespace(bean), values
getNamespace(enumType, bean.getClassInfo()), values
), bean);
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
package com.fasterxml.jackson.dataformat.avro.annotations;

import com.fasterxml.jackson.databind.JsonMappingException;
import com.fasterxml.jackson.dataformat.avro.AvroMapper;
import com.fasterxml.jackson.dataformat.avro.annotation.AvroNamespace;
import com.fasterxml.jackson.dataformat.avro.schema.AvroSchemaGenerator;

import org.apache.avro.Schema;

import org.junit.Test;

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

@Test
public void class_without_AvroNamespace_test() throws JsonMappingException {
public void class_without_AvroNamespace_test() throws Exception {
// GIVEN
AvroMapper mapper = new AvroMapper();
AvroSchemaGenerator gen = new AvroSchemaGenerator();
Expand All @@ -39,7 +40,7 @@ public void class_without_AvroNamespace_test() throws JsonMappingException {
}

@Test
public void class_with_AvroNamespace_test() throws JsonMappingException {
public void class_with_AvroNamespace_test() throws Exception {
// GIVEN
AvroMapper mapper = new AvroMapper();
AvroSchemaGenerator gen = new AvroSchemaGenerator();
Expand All @@ -54,7 +55,7 @@ public void class_with_AvroNamespace_test() throws JsonMappingException {
}

@Test
public void enum_without_AvroNamespace_test() throws JsonMappingException {
public void enum_without_AvroNamespace_test() throws Exception {
// GIVEN
AvroMapper mapper = new AvroMapper();
AvroSchemaGenerator gen = new AvroSchemaGenerator();
Expand All @@ -69,7 +70,7 @@ public void enum_without_AvroNamespace_test() throws JsonMappingException {
}

@Test
public void enum_with_AvroNamespace_test() throws JsonMappingException {
public void enum_with_AvroNamespace_test() throws Exception {
// GIVEN
AvroMapper mapper = new AvroMapper();
AvroSchemaGenerator gen = new AvroSchemaGenerator();
Expand Down

0 comments on commit d733d03

Please sign in to comment.