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

Allow ability to specify serialization key for fields instead of always defaulting to field name #119

Open
antoinesaliba opened this issue Jul 19, 2024 · 0 comments

Comments

@antoinesaliba
Copy link
Collaborator

Goal: Be able to build a struct from another struct even if the field names are different

Context: Serializing a struct currently always makes the keys the name of the fields, this makes this flow not work if you want to build one struct from another:

  1. struct1 has a field income_type
  2. you serialize your instance of struct1 to a hash
  3. you deserialize the hash to build struct2 which has a single field called type

step 3 will raise an error Typed::Validations::RequiredFieldError: type is required. because the hash doesn't have a key for type, but it has a key for `income_type.

Ideally, it'd be great to specify a target for each field. If target is specified, that's what is used for the key name instead of the field name.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant