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

Combine parent child serializer. #260

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open

Conversation

chyipin
Copy link

@chyipin chyipin commented Jun 2, 2015

Extend child serializer to merge serialized data for parent serializer with same fields.

Currently, child serializer for specific fields will override the parent serializer. This prevents custom serialization at parent level.
Parent:

        serializers: {
            req: function (req) {
              return {
                username: req.user.username
              };
            }
        }

Child:

        serializers: {
            req: function (req) {
              return {
                // other fields: timers, stats, etc
              };
            }
        }

Primary use case is restify audit logger.
The proposed changes applies the serializers from parent and child, and merge the serialized result preferring the data from the child if there are field collision (similar to a simple `_.merge). If there happens to be a clash in field names, the fix would be to change the field name for the serializer in the parent.

Extend child serializer to merge serialized data for parent serializer with same fields.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants