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 shallow encoding a class #141

Merged
merged 3 commits into from
Dec 6, 2023
Merged

Allow shallow encoding a class #141

merged 3 commits into from
Dec 6, 2023

Conversation

SchoofsEbert
Copy link
Contributor

@SchoofsEbert SchoofsEbert commented Oct 23, 2023

When encoding a custom class, you don't always want to go all the way down to the primitives.
Sometimes you want to convert the object to a Map, e.g. to dynamically access field values for forms for example, but want to keep the types of the attributes when extracting them.

This PR generates a new method toShallowMap that converts the object to a map, but not the values of its attributes.

A new test case has been added to verify the correctness of the implementation.

If this does not follow the general idea of dart_mappable, is there a way we can implement this outside of the package?

@schultek
Copy link
Owner

Hi. I would be find with adding this to the EncodingOptions as you did, but not to the generated Mappable mixins. So then to use it you need to call return MyClassMapper.ensureInitialized() .encodeMap<MyClass>(myClass, EncodingOptions(shallow: true)); manually.

If that works for you I'm happy to merge this pr once its adjusted.

@SchoofsEbert
Copy link
Contributor Author

The generation of the toShallowMap methods in the mixins has been removed.

@SchoofsEbert
Copy link
Contributor Author

@schultek Do you have any other requirements before the PR can be merged?

Copy link
Owner

@schultek schultek left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sry did't had time to check yet. LGTM

@schultek schultek merged commit cc41562 into schultek:main Dec 6, 2023
1 check failed
@SchoofsEbert SchoofsEbert deleted the shallow_map branch December 7, 2023 15:32
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

Successfully merging this pull request may close these issues.

2 participants