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

Preserve empty JSON types #81

Merged
merged 4 commits into from
Jun 7, 2019
Merged

Preserve empty JSON types #81

merged 4 commits into from
Jun 7, 2019

Conversation

justincampbell
Copy link
Contributor

@justincampbell justincampbell commented May 22, 2019

The existing behavior when specifying serializer: :json was to store and return an empty Hash ({}) for null or empty values, including empty arrays or nil.

This changes the encode logic to store the JSON representation of any given value. During decode, any valid JSON string can be decoded. We special case nil or "" (empty string) to return nil (instead of {} previously).

This will be a breaking change for applications that depend on the empty hash == nil behavior.

@justincampbell justincampbell force-pushed the json-serializer-values branch 2 times, most recently from 5abc923 to 675eccb Compare May 22, 2019 17:48
The existing behavior when specifying `serializer: :json` was to store
and return an empty Hash (`{}`) for null or empty values, including
empty arrays.

This changes the encode logic to store the JSON representation of
any given value. During decode, any valid JSON string can be decoded. We
special case `nil` or `""` (empty string) to return `nil` (instead of
`{}` previously).

This could be a breaking for applications that depend on the empty hash
== nil behavior.
Copy link

@findkim findkim left a comment

Choose a reason for hiding this comment

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

The changes look good and make sense from a JSON standpoint. We discussed that this is no longer compatible with some Ruby versions and that'll be documented in a follow-up changelog

@justincampbell justincampbell merged commit 35031d4 into master Jun 7, 2019
@justincampbell justincampbell deleted the json-serializer-values branch June 7, 2019 15:31
justincampbell added a commit that referenced this pull request Jun 10, 2019
This adds a `:default` option to `vault_attribute`, allowing a default value to be set if the underlying value is `nil`.

```rb
vault_attribute :metadata,
  serializer: :json,
  default: {}

vault_attribute :access_level,
  default: "readonly"
```

This enables a simple fix for applications affected by the breaking change introduced in #81 for `serialize: :json` empty values.
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.

None yet

2 participants