Skip to content

ignore_nil! doesn't work for nil object values within array #363

Closed
@aubergene

Description

@aubergene

This test demonstrates my issue

test 'ignore_nil! within array' do
  result = jbuild do |json|
    json.ignore_nil! true
    json.array! [{ name: 'Bob', dne: nil }]
  end

  assert_equal ['name'], result[0].keys

  result = jbuild do |json|
    json.ignore_nil! false
    json.array! [{ name: 'Bob', dne: nil }]
  end

  assert_equal ['name', 'dne'], result[0].keys
end

I'm afraid I couldn't work out how to fix it. Additionally I noticed that the test shows a symbol key is returned instead of a key, which might be related to the issue.

  diff:
  - ["name", "dne"]
  ?  ^    -  ^   -
  + [:name, :dne]

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions