Enable use of an object
key in serilaized forms
#1354
Closed
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Because all serializers already implement an
object
method (part of the API expected when customizing a serializer), attempting to add a key to the serialized object with the nameobject
would not output the expected value, and would instead dump a serialized version of the object under serialization.This prevents a commonly used identifier from appearing in serialized output. As one real world example, the Stripe API includes an
object
key in each serialized object describing its type.I introduced a change in the storage for the serializer configuration, and added methods to access it in the same way as before. Open question: I stored the key/attribute mapping in a Hash<Symbol => Symbol>; would the project be better served mapping to a nested hash to support additional configuration options in the future without changing the storage again?
This may have introduced a breaking change; before, methods were defined on the serializer based on the name of the key; now they will be defined based on the name of the underlying attribute. This behavior doesn't seem to be explicitly mentioned in docs or tested anywhere, though, so it may be a non-issue.