Skip to content

Commit

Permalink
Merge pull request #445 from cedarcode/sr--fix-serializer
Browse files Browse the repository at this point in the history
Fix `PublicKeyCredential::Options#.as_json` not camelCase'ing keys of attributes with hash or arrays as values
  • Loading branch information
brauliomartinezlm authored Nov 14, 2024
2 parents 00b30c5 + 94d4607 commit c385f25
Showing 1 changed file with 8 additions and 6 deletions.
14 changes: 8 additions & 6 deletions lib/webauthn/json_serializer.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,19 +4,21 @@ module WebAuthn
module JSONSerializer
# Argument wildcard for Ruby on Rails controller automatic object JSON serialization
def as_json(*)
to_hash_with_camelized_keys
deep_camelize_keys(to_hash)
end

private

def to_hash_with_camelized_keys
def to_hash
attributes.each_with_object({}) do |attribute_name, hash|
value = send(attribute_name)

if value && value.respond_to?(:as_json)
hash[camelize(attribute_name)] = value.as_json
elsif value
hash[camelize(attribute_name)] = deep_camelize_keys(value)
if value.respond_to?(:as_json)
value = value.as_json
end

if value
hash[attribute_name] = value
end
end
end
Expand Down

0 comments on commit c385f25

Please sign in to comment.