[Fixes #14948] Hash#to_query: Changed a way how empty hash and empty array are serialized

Empty Hash or Array should not present in serialization result

    {a: []}.to_query # => ""
    {a: {}}.to_query # => ""

For more info see #14948.