question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Any guidance on implementing serialization from/deserialization to custom classes?

See original GitHub issue

It’s often perfectly fine to serialize dicts/lists/etc into avro, and deserialize avro into dicts/lists/etc. However sometimes it would be nice to use custom classes to hold the data while it’s in Python.

This is possible in the standard python JSON module, for example, using the object_hook argument. Something similar should be possible in avro. For deserializing, a function could take schema and object as arguments where object is whatever dict/list/etc was parsed, and schema is the avro schema of that object. The function body could then make a decision on whether to return the default object or instantiate a new object to return.

I’m curious how I might begin to implement something like this using the fastavro library. If anyone has any guidance, I’d really appreciate it.

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Comments:20 (2 by maintainers)

github_iconTop GitHub Comments

1reaction
scottbeldencommented, Apr 19, 2019

@redsk Cool! I’m interested to take a look at it, so hopefully I can do that soon.

1reaction
redskcommented, Apr 17, 2019

Hi @scottbelden , I’ve written an open source library to generate python classes from avro schemas. It’s available at https://gitlab.com/Jaumo/pyavro-gen . It also includes some bits to integrate it with fastavro, Kafka and the Schema Registry (as this is required for my use case).

I also used dataclasses (python 3.7) but I guess it would be possible to consider support for older versions as well.

Please let me know if you’re interested.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Serialization guidelines | Microsoft Learn
This document provides guidelines to consider when designing an API to be serialized and a summary of the different serialization ...
Read more >
Everything You Need to Know About Java Serialization ...
Check out this post to learn everything you need to know about serialization in Java and what this looks like in code examples....
Read more >
SER00-J. Enable serialization compatibility during class
To enable compatible evolution of a serializable class, developers must use a custom serialized form, which is more flexible than a default form....
Read more >
Effective Java - Serialization - Qoders Blog ·
It decreases the flexibility to change a class's implementation once it has been released, because the serialized form because a part of the ......
Read more >
Different Serialization Approaches for Java - Baeldung
3.2. Custom Serialization Using the Externalizable Interface ... We can implement these two methods inside the class that we want to serialize. A ......
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found