File tree Expand file tree Collapse file tree 4 files changed +77
-0
lines changed
main/java/com/github/fge/jsonschema2avro
java/com/github/fge/jsonschema2avro
resources/jsonschema2avro Expand file tree Collapse file tree 4 files changed +77
-0
lines changed Original file line number Diff line number Diff line change 12
12
import com .github .fge .jsonschema .util .JsonLoader ;
13
13
import com .github .fge .jsonschema .util .ValueHolder ;
14
14
import com .github .fge .jsonschema2avro .writers .ArrayWriter ;
15
+ import com .github .fge .jsonschema2avro .writers .MapWriter ;
15
16
import com .github .fge .jsonschema2avro .writers .SimpleTypeWriter ;
16
17
import org .apache .avro .Schema ;
17
18
@@ -29,6 +30,7 @@ public AvroWriterProcessor()
29
30
processor = new ProcessorSelector <AvroPayload , ValueHolder <Schema >>()
30
31
.when (simpleType ()).then (SimpleTypeWriter .getInstance ())
31
32
.when (array ()).then (ArrayWriter .getInstance ())
33
+ .when (map ()).then (MapWriter .getInstance ())
32
34
.getProcessor ();
33
35
}
34
36
Original file line number Diff line number Diff line change
1
+ package com .github .fge .jsonschema2avro .writers ;
2
+
3
+ import com .github .fge .jsonschema .exceptions .ProcessingException ;
4
+ import com .github .fge .jsonschema .jsonpointer .JsonPointer ;
5
+ import com .github .fge .jsonschema .processors .data .SchemaHolder ;
6
+ import com .github .fge .jsonschema .report .ProcessingReport ;
7
+ import com .github .fge .jsonschema .tree .SchemaTree ;
8
+ import com .github .fge .jsonschema2avro .AvroWriterProcessor ;
9
+ import org .apache .avro .Schema ;
10
+
11
+ public final class MapWriter
12
+ extends AvroWriter
13
+ {
14
+ private static final JsonPointer POINTER
15
+ = JsonPointer .of ("additionalProperties" );
16
+
17
+ private static final AvroWriter INSTANCE = new MapWriter ();
18
+
19
+ private MapWriter ()
20
+ {
21
+ }
22
+
23
+ public static AvroWriter getInstance ()
24
+ {
25
+ return INSTANCE ;
26
+ }
27
+
28
+ @ Override
29
+ protected Schema generate (final AvroWriterProcessor writer ,
30
+ final ProcessingReport report , final SchemaTree tree )
31
+ throws ProcessingException
32
+ {
33
+ final SchemaHolder input = new SchemaHolder (tree .append (POINTER ));
34
+ final Schema valueSchema = writer .process (report , input ).getValue ();
35
+ return Schema .createMap (valueSchema );
36
+ }
37
+ }
Original file line number Diff line number Diff line change
1
+ package com .github .fge .jsonschema2avro ;
2
+
3
+ import java .io .IOException ;
4
+
5
+ public final class MapTest
6
+ extends AvroWriterProcessorTest
7
+ {
8
+ public MapTest ()
9
+ throws IOException
10
+ {
11
+ super ("map" );
12
+ }
13
+ }
Original file line number Diff line number Diff line change
1
+ [
2
+ {
3
+ "jsonSchema" : {
4
+ "type" : " object" ,
5
+ "additionalProperties" : { "type" : " string" }
6
+ },
7
+ "avroSchema" : {
8
+ "type" : " map" ,
9
+ "values" : " string"
10
+ }
11
+ },
12
+ {
13
+ "jsonSchema" : {
14
+ "type" : " object" ,
15
+ "additionalProperties" : {
16
+ "type" : " array" ,
17
+ "items" : { "type" : " number" }
18
+ }
19
+ },
20
+ "avroSchema" : {
21
+ "type" : " map" ,
22
+ "values" : { "type" : " array" , "items" : " double" }
23
+ }
24
+ }
25
+ ]
You can’t perform that action at this time.
0 commit comments