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.

(De)serialization to other types

See original GitHub issue

I’d love for Marshmallow to be more modular, for example I’m loading from JSON and serializing to bencode. It would be great if there was a simple way to do this.

It was suggested in https://github.com/marshmallow-code/marshmallow/issues/130 but the solution assumes that the source and destination encoding are the same.

Issue Analytics

  • State:closed
  • Created 6 years ago
  • Comments:7 (6 by maintainers)

github_iconTop GitHub Comments

4reactions
sloriacommented, Oct 18, 2018

Ah, I see. OK, for now I’d recommend implementing a custom render class that implements dumps and loads.

class ComboRenderer:
    @staticmethod
    def loads(s, *args, **kwargs):
        return json.loads(s, *args, **kwargs)

    @staticmethod
    def dumps(obj, *args, **kwargs):
        return yaml.dumps(obj, *args, **kwargs)


class MySchema(Schema):
    class Meta:
        render_module = ComboRenderer
1reaction
lafrechcommented, Apr 11, 2018

I was about to close this as this is a corner case and the two-schema solution seems reasonable enough.

OTOH, this would be really easy to achieve, all it takes is a load_render_module and a dump_render_module rather than just render_module.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Deserialization - OWASP Cheat Sheet Series
Deserialization is the reverse of that process, taking data structured from some format, and rebuilding it into an object. Today, the most popular...
Read more >
Serialization and deserialization in Java | Snyk Blog
Java serialization is a mechanism to transform an object into a byte stream. Java deserialization, on the other hand, allows us to recreate ......
Read more >
Understanding Java De-serialization | by Swapneil Kumar Dash
Here I will be discussing on the the category of JAVA deserialization which is human unreadable like binary data as opposed to other...
Read more >
Deserialization - HackTricks
Deserialization is the reverse of that process, taking data structured from some format, and rebuilding it into an object. Today, the most popular...
Read more >
Serializing/deserializing System.Object using a different type
Making ZoneProgramInput take a generic type parameter and making Value of that type still serializes/deserializes Value as a string. I also ...
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