iDigBio / idigbio-search-api

Server-side code driving iDigBio's search functionality.
GNU General Public License v3.0
24 stars 5 forks source link

Query field exists/absent doesn't accept lists from R #2

Closed mjcollin closed 9 years ago

mjcollin commented 9 years ago

R treats everything as a vector so when httr JSON encodes list("geopoint"=list("type"="exists")) the result is

{
  "geopoint": {
    "type": ["exists"]
  }
}

This returns a 400 invalid request. The JSON with "exists" works fine.

godfoder commented 9 years ago

I hesitate to call this a bug in HTTR, but it certainly is an issue: https://github.com/hadley/httr/issues/159

That has some workarounds to use a different JSON,

It also seems like:

httr::POST('https://api.hipchat.com/v2/rooms/room_id/notification?auth_token=token',
  body = jsonlite::toJSON(list(message = 'hello hipchat'),auto_unbox=TRUE), 
  httr::content_type_json())

Would work without switching encoders to rjson. It doesn't seem like anyone is interested in fixing this, but "I refuse to treat single item lists the same as literals, because my language chooses to treat literals as single item lists" doesn't seem like an argument that holds much water.

Since workarounds exist, I'm going to wontfix this.

godfoder commented 9 years ago

At least they're thinking about it again: https://github.com/hadley/httr/issues/187 https://github.com/jeroenooms/jsonlite/issues/73

jeroen commented 9 years ago

You're welcome to joint he discussion and argue about which defaults you would like to see, or how we can make it easier to set toJSON parameters in httr.