3
3
import java .util .ArrayList ;
4
4
import java .util .List ;
5
5
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 .*;
12
11
import com .fasterxml .jackson .databind .jsonFormatVisitors .JsonFormatVisitable ;
13
12
import com .fasterxml .jackson .databind .jsonFormatVisitors .JsonObjectFormatVisitor ;
14
13
import com .fasterxml .jackson .databind .ser .BeanPropertyWriter ;
15
14
import com .fasterxml .jackson .dataformat .avro .AvroFixedSize ;
16
15
17
- import org .apache .avro .Schema ;
18
- import org .apache .avro .reflect .AvroMeta ;
19
- import org .apache .avro .reflect .AvroSchema ;
20
-
21
16
public class RecordVisitor
22
17
extends JsonObjectFormatVisitor .Base
23
18
implements SchemaBuilder
@@ -26,9 +21,13 @@ public class RecordVisitor
26
21
27
22
protected final DefinedSchemas _schemas ;
28
23
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 ;
30
29
31
- protected boolean _overridden ;
30
+ protected Schema _avroSchema ;
32
31
33
32
protected List <Schema .Field > _fields = new ArrayList <Schema .Field >();
34
33
@@ -38,17 +37,15 @@ public RecordVisitor(SerializerProvider p, JavaType type, DefinedSchemas schemas
38
37
_type = type ;
39
38
_schemas = schemas ;
40
39
// 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 );
43
42
if (ann != null ) {
44
- Schema .Parser parser = new Schema .Parser ();
45
- _avroSchema = parser .parse (ann .value ());
43
+ _avroSchema = AvroSchemaHelper .parseJsonSchema (ann .value ());
46
44
_overridden = true ;
47
45
} 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 );
50
47
_overridden = false ;
51
- AvroMeta meta = ac .getAnnotation (AvroMeta .class );
48
+ AvroMeta meta = bean . getClassInfo () .getAnnotation (AvroMeta .class );
52
49
if (meta != null ) {
53
50
_avroSchema .addProp (meta .key (), meta .value ());
54
51
}
@@ -163,8 +160,7 @@ protected Schema.Field schemaFieldForWriter(BeanProperty prop, boolean optional)
163
160
writerSchema = AvroSchemaHelper .unionWithNull (writerSchema );
164
161
}
165
162
}
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 );
168
164
169
165
AvroMeta meta = prop .getAnnotation (AvroMeta .class );
170
166
if (meta != null ) {
0 commit comments