JSON Schema support
See original GitHub issueIs your feature request related to a problem? Please describe.
I was wondering if support for JSON schemas was something you would be interested in having added? We are currently using confluent kafka and the schema registry to manage json schemas. We are using faust to process the data using the schema registry, and would love to be able to utilize and contribute to this library. Notably json schema support for the FaustSerializer
would be great.
I would be happy to work with you to try submit a pull request. I would value guidance on your thoughts of how it should work and what the major changes might be.
As I see it the following is probably a good start.
- Abstract most of what is currently
AvroSchema
class into a new abstract base class and create new child classesAvroSchema
andJsonSchema
. Also makeload
andasync_load
static methods respectively on the classes. - Update the serializer classes and factory. Open to ideas on exactly what should be updated here and how it would determine between avro and json schemas. Perhaps an argument given in
__init__
? Or perhaps distinct separate classes for avro vs json serialization? - Update all type references
- Write new tests
Currently if you try use a json schema in the serializer and call _dumps
you get the following exception.
File "d:\scratch\python-schema-registry-client\schema_registry\serializers\faust_serializer.py", line 50, in _dumps
return self.encode_record_with_schema(self.schema_subject, self.schema, payload) # type: ignore
File "d:\scratch\python-schema-registry-client\schema_registry\serializers\message_serializer.py", line 73, in encode_record_with_schema
schema_id = self.schemaregistry_client.register(subject, avro_schema)
File "d:\scratch\python-schema-registry-client\schema_registry\client\client.py", line 252, in register
avro_schema = AvroSchema(avro_schema)
File "d:\scratch\python-schema-registry-client\schema_registry\client\schema.py", line 13, in __init__
File "fastavro\_schema.pyx", line 78, in fastavro._schema.parse_schema
File "fastavro\_schema.pyx", line 254, in fastavro._schema._parse_schema
fastavro._schema_common.UnknownType
Describe the solution you’d like
I would like to be able to pass json schemas to the FaustSerializer
and have it serialize and deserialize objects correctly without an exception.
e.g. something like.
serializer = FaustSerializer(schema_registry_client, type(MyClass).__name__, MyClass.schema_json())
serializer._dumps(MyClass())
Issue Analytics
- State:
- Created 2 years ago
- Comments:5 (5 by maintainers)
Top GitHub Comments
Thanks @Robospecta !!
Thanks @marcosschroh. Apologies for the delay, we’ve actually moved away from Faust and Kafka for the time being. Thankfully I had already completed this work.
I have submitted a pull request, and tried to minimize any breaking changes. Hopefully the changes are acceptable, if anything needs addressing, or any issues arise after release, feel free to tag me.