Skip to content

Commit

Permalink
Autounbox json
Browse files Browse the repository at this point in the history
Fixes #187
  • Loading branch information
hadley committed May 4, 2015
1 parent b0723f1 commit e30854c
Show file tree
Hide file tree
Showing 6 changed files with 21 additions and 5 deletions.
4 changes: 4 additions & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
# httr 0.6.1.9000

* `POST(encode = 'json')` now automatically turns length-1 vectors into json
scalars. To prevent this automatic "unboxing", wrap the vector in `I()`
(#187).

# httr 0.6.1

* Correctly parse headers with multiple `:`, thanks to @mmorgan (#180).
Expand Down
2 changes: 1 addition & 1 deletion R/body.R
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ body_config <- function(body = NULL, encode = "form", type = NULL) {
if (encode == "form") {
body_raw(compose_query(body), "application/x-www-form-urlencoded")
} else if (encode == "json") {
body_raw(jsonlite::toJSON(body), "application/json")
body_raw(jsonlite::toJSON(body, auto_unbox = TRUE), "application/json")
} else if (encode == "multipart") {
# For multipart, rely on RCurl .postForm function to make it possible
# to intermingle on-disk and in-memory content.
Expand Down
5 changes: 4 additions & 1 deletion R/http-post.r
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,10 @@
#'
#' For "multipart", list elements can be strings or objects created by
#' \code{\link{upload_file}}. For "form", elements are coerced to strings
#' and escaped, use \code{I()} to prevent double-escaping.
#' and escaped, use \code{I()} to prevent double-escaping. For "json",
#' parameters are automatically "unboxed" (i.e. length 1 vectors are
#' converted to scalars). To preserve a length 1 vector as a vector,
#' wrap in \code{I()}.
#' @param multipart Deprecated. \code{TRUE} = \code{encode = "multipart"},
#' \code{FALSE} = {encode = "form"}.
#' Files can not be uploaded when \code{FALSE}.
Expand Down
5 changes: 4 additions & 1 deletion man/PATCH.Rd
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,10 @@ with \code{\link{config}}.}

For "multipart", list elements can be strings or objects created by
\code{\link{upload_file}}. For "form", elements are coerced to strings
and escaped, use \code{I()} to prevent double-escaping.}
and escaped, use \code{I()} to prevent double-escaping. For "json",
parameters are automatically "unboxed" (i.e. length 1 vectors are
converted to scalars). To preserve a length 1 vector as a vector,
wrap in \code{I()}.}

\item{multipart}{Deprecated. \code{TRUE} = \code{encode = "multipart"},
\code{FALSE} = {encode = "form"}.
Expand Down
5 changes: 4 additions & 1 deletion man/POST.Rd
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,10 @@ with \code{\link{config}}.}

For "multipart", list elements can be strings or objects created by
\code{\link{upload_file}}. For "form", elements are coerced to strings
and escaped, use \code{I()} to prevent double-escaping.}
and escaped, use \code{I()} to prevent double-escaping. For "json",
parameters are automatically "unboxed" (i.e. length 1 vectors are
converted to scalars). To preserve a length 1 vector as a vector,
wrap in \code{I()}.}

\item{multipart}{Deprecated. \code{TRUE} = \code{encode = "multipart"},
\code{FALSE} = {encode = "form"}.
Expand Down
5 changes: 4 additions & 1 deletion man/PUT.Rd
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,10 @@ with \code{\link{config}}.}

For "multipart", list elements can be strings or objects created by
\code{\link{upload_file}}. For "form", elements are coerced to strings
and escaped, use \code{I()} to prevent double-escaping.}
and escaped, use \code{I()} to prevent double-escaping. For "json",
parameters are automatically "unboxed" (i.e. length 1 vectors are
converted to scalars). To preserve a length 1 vector as a vector,
wrap in \code{I()}.}

\item{multipart}{Deprecated. \code{TRUE} = \code{encode = "multipart"},
\code{FALSE} = {encode = "form"}.
Expand Down

0 comments on commit e30854c

Please sign in to comment.