Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: avro-json serialization with defaults #89

Merged
merged 1 commit into from
Jan 27, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
fix: avro-json serialization with defaults
  • Loading branch information
marcosschroh committed Jan 25, 2021
commit 6baf5c8de8201d052f9ffc6b2f0a5eb64c19abb7
2 changes: 1 addition & 1 deletion requirements.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
fastavro
fastavro==1.3.0
inflect
pytz
faust==1.9.0
Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
long_description=long_description,
long_description_content_type="text/markdown",
author="Marcos Schroh",
install_requires=["inflect", "fastavro", "pytz", "dacite", "faker",],
install_requires=["inflect", "fastavro==1.3.0", "pytz", "dacite", "faker",],
author_email="schrohm@gmail.com",
url="https://github.com/marcosschroh/dataclasses-avroschema",
download_url="",
Expand Down
2 changes: 1 addition & 1 deletion tests/serialization/test_nested_schema_serialization.py
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ class User(AvroModel):
assert user.serialize() == avro_binary

# Bug in fastavro
# assert user.serialize(serialization_type="avro-json") == avro_json_binary
assert user.serialize(serialization_type="avro-json") == avro_json_binary

assert User.deserialize(avro_binary, create_instance=False) == expected
assert User.deserialize(avro_json_binary, serialization_type="avro-json", create_instance=False) == expected
Expand Down
15 changes: 14 additions & 1 deletion tests/serialization/test_primitive_types_serialization.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,6 @@ class User(AvroModel):
encoded: bytes = b"hola"

data = {"name": "marcos", "age": 20, "has_pets": False, "money": 100.0, "encoded": b"hola"}

data_json = {"name": "marcos", "age": 20, "has_pets": False, "money": 100.0, "encoded": "hola"}

user = User()
Expand All @@ -47,6 +46,20 @@ class User(AvroModel):

assert user.to_json() == data_json

# check that works with schema evolution
user = User(name="Juan", age=30)
avro_json = user.serialize(serialization_type="avro-json")

data = {"name": "Juan", "age": 30, "has_pets": False, "money": 100.0, "encoded": b"hola"}
data_json = {"name": "Juan", "age": 30, "has_pets": False, "money": 100.0, "encoded": "hola"}

# assert user.deserialize(avro_binary, create_instance=False) == data
assert user.deserialize(avro_json, serialization_type="avro-json", create_instance=False) == data

# assert user.deserialize(avro_binary) == user
assert user.deserialize(avro_json, serialization_type="avro-json") == user
assert user.to_json() == data_json


def test_primitive_types_with_nulls():
@dataclass
Expand Down