[Fixes #14948] Hash#to_query: right serialization for  empty hash and array

Empty Hash or Array should not present in serialization result

``` ruby
{a: []}.to_query # => ""
{a: {}}.to_query # => ""
```

For more info see #14948.