[Core] Specify the serializer for a certain object
See original GitHub issueDescribe your feature request
The default serializer has many issues with certain objects. One case is the pydantic model. We can specify a flag __ray_serializer__ in these object types to enforce ray using pickle as the default serializer instead. This avoids changing other functions like ray.put, ray.remote and xxxx.remote(...). This could also cover our major cases and is super flexible.
One example could be:
from pydantic import BaseModel, validator
class UserModel(BaseModel):
__ray_serializer__ = 'pickle'
name: str
username: str
password1: str
password2: str
@validator('name')
def name_must_contain_space(cls, v):
if ' ' not in v:
raise ValueError('must contain a space')
return v.title()
@validator('password2')
def passwords_match(cls, v, values, **kwargs):
if 'password1' in values and v != values['password1']:
raise ValueError('passwords do not match')
return v
@validator('username')
def username_alphanumeric(cls, v):
assert v.isalnum(), 'must be alphanumeric'
return v
Issue Analytics
- State:
- Created 3 years ago
- Reactions:1
- Comments:6 (6 by maintainers)
Top Results From Across the Web
How to serialize and deserialize JSON using C# - .NET
NET objects as JSON (serialize); Serialize to UTF-8; Serialization behavior ... NET Core app, some default behaviors are different.
Read more >Json.net serialize only certain properties - Stack Overflow
If you have a property on your object that is null or the default value, you can let json.net ignore it and NOT...
Read more >System.Text.Json: How to serialize only certain properties ...
We want that when we serialize it with our own JsonSerializer we add our customization to only allow certain properties. 2- For security...
Read more >Serializing Django objects — Django 4.1.3 documentation
Each field of the object is serialized as a <field> -element sporting the fields “type” and “name”. The text content of the element...
Read more >Object serialization - R3 Documentation
The primary way Corda's AMQP serialization framework instantiates objects is via a specified constructor. This is used to first determine which properties ...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found

yeah, a trivial solution is to overload
__reduce__with pickle.dumps, so cloudpickle then serialize the pickled content again.I think @pcmoritz has a great idea here:
Now I just need to define unparse as: