33import java .util .ArrayList ;
44import java .util .List ;
55
6- import com .fasterxml .jackson .databind .BeanProperty ;
7- import com .fasterxml .jackson .databind .JavaType ;
8- import com .fasterxml .jackson .databind .JsonMappingException ;
9- import com .fasterxml .jackson .databind .JsonSerializer ;
10- import com .fasterxml .jackson .databind .SerializerProvider ;
11- import com .fasterxml .jackson .databind .introspect .AnnotatedClass ;
6+ import org .apache .avro .Schema ;
7+ import org .apache .avro .reflect .AvroMeta ;
8+ import org .apache .avro .reflect .AvroSchema ;
9+
10+ import com .fasterxml .jackson .databind .*;
1211import com .fasterxml .jackson .databind .jsonFormatVisitors .JsonFormatVisitable ;
1312import com .fasterxml .jackson .databind .jsonFormatVisitors .JsonObjectFormatVisitor ;
1413import com .fasterxml .jackson .databind .ser .BeanPropertyWriter ;
1514import com .fasterxml .jackson .dataformat .avro .AvroFixedSize ;
1615
17- import org .apache .avro .Schema ;
18- import org .apache .avro .reflect .AvroMeta ;
19- import org .apache .avro .reflect .AvroSchema ;
20-
2116public class RecordVisitor
2217 extends JsonObjectFormatVisitor .Base
2318 implements SchemaBuilder
@@ -26,9 +21,13 @@ public class RecordVisitor
2621
2722 protected final DefinedSchemas _schemas ;
2823
29- protected Schema _avroSchema ;
24+ /**
25+ * Tracks if the schema for this record has been overridden (by an annotation or other means), and calls to the {@code property} and
26+ * {@code optionalProperty} methods should be ignored.
27+ */
28+ protected final boolean _overridden ;
3029
31- protected boolean _overridden ;
30+ protected Schema _avroSchema ;
3231
3332 protected List <Schema .Field > _fields = new ArrayList <Schema .Field >();
3433
@@ -38,17 +37,15 @@ public RecordVisitor(SerializerProvider p, JavaType type, DefinedSchemas schemas
3837 _type = type ;
3938 _schemas = schemas ;
4039 // Check if the schema for this record is overridden
41- AnnotatedClass ac = getProvider ().getConfig ().introspectDirectClassAnnotations (_type ). getClassInfo ( );
42- AvroSchema ann = ac .getAnnotation (AvroSchema .class );
40+ BeanDescription bean = getProvider ().getConfig ().introspectDirectClassAnnotations (_type );
41+ AvroSchema ann = bean . getClassInfo () .getAnnotation (AvroSchema .class );
4342 if (ann != null ) {
44- Schema .Parser parser = new Schema .Parser ();
45- _avroSchema = parser .parse (ann .value ());
43+ _avroSchema = AvroSchemaHelper .parseJsonSchema (ann .value ());
4644 _overridden = true ;
4745 } else {
48- String description = getProvider ().getAnnotationIntrospector ().findClassDescription (ac );
49- _avroSchema = Schema .createRecord (AvroSchemaHelper .getName (type ), description , AvroSchemaHelper .getNamespace (type ), false );
46+ _avroSchema = AvroSchemaHelper .initializeRecordSchema (bean );
5047 _overridden = false ;
51- AvroMeta meta = ac .getAnnotation (AvroMeta .class );
48+ AvroMeta meta = bean . getClassInfo () .getAnnotation (AvroMeta .class );
5249 if (meta != null ) {
5350 _avroSchema .addProp (meta .key (), meta .value ());
5451 }
@@ -163,8 +160,7 @@ protected Schema.Field schemaFieldForWriter(BeanProperty prop, boolean optional)
163160 writerSchema = AvroSchemaHelper .unionWithNull (writerSchema );
164161 }
165162 }
166- String description = getProvider ().getAnnotationIntrospector ().findPropertyDescription (prop .getMember ());
167- Schema .Field field = new Schema .Field (prop .getName (), writerSchema , description , null );
163+ Schema .Field field = new Schema .Field (prop .getName (), writerSchema , prop .getMetadata ().getDescription (), null );
168164
169165 AvroMeta meta = prop .getAnnotation (AvroMeta .class );
170166 if (meta != null ) {
0 commit comments