From 57a78525a25be7f067092719aaff3bfbfbaaac16 Mon Sep 17 00:00:00 2001 From: Jeremy Werner Date: Wed, 18 Oct 2017 12:40:46 -0500 Subject: [PATCH 1/3] Change POST default json conversion digits to 22 --- R/body.R | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/R/body.R b/R/body.R index 9985eb97..c0fd5d8e 100644 --- a/R/body.R +++ b/R/body.R @@ -51,7 +51,8 @@ body_config <- function(body = NULL, } else if (encode == "form") { body_raw(compose_query(body), "application/x-www-form-urlencoded") } else if (encode == "json") { - body_raw(jsonlite::toJSON(body, auto_unbox = TRUE), "application/json") + body_raw(jsonlite::toJSON(body, auto_unbox = TRUE, digits = 22), + "application/json") } else if (encode == "multipart") { if (!all(has_name(body))) stop("All components of body must be named", call. = FALSE) From 57cc92864007ae1fd1b01248ab5eb3a30b635acc Mon Sep 17 00:00:00 2001 From: Jeremy Werner Date: Wed, 18 Oct 2017 12:42:23 -0500 Subject: [PATCH 2/3] Add test for retaining decimal precision in POST request with json encoding --- tests/testthat/test-body.r | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/tests/testthat/test-body.r b/tests/testthat/test-body.r index a8019bc3..3c292463 100644 --- a/tests/testthat/test-body.r +++ b/tests/testthat/test-body.r @@ -59,6 +59,12 @@ test_that("named list matches form results (encode = 'json')", { expect_equal(out$json$b[[1]], 2) }) +test_that("decimal precision is preserved (encode = 'json')", { + out <- round_trip(body = list(a = 0.8675309867530986753098675309), + encode = "json") + expect_equal(out$data, "{\"a\":0.867530986753099}") +}) + test_that("can do own encoding", { out <- round_trip(body = '{"a":1,"b":2}', content_type_json(), encode = "raw") expect_equal(out$json, list(a = 1, b = 2)) From 9019e773f85ed924c647b6d6c94128c4b6fdced4 Mon Sep 17 00:00:00 2001 From: Jeremy Werner Date: Wed, 21 Nov 2018 17:29:42 -0800 Subject: [PATCH 3/3] Add description of POST default behavior change for PR #490 --- NEWS.md | 3 +++ 1 file changed, 3 insertions(+) diff --git a/NEWS.md b/NEWS.md index db3da849..40c71006 100644 --- a/NEWS.md +++ b/NEWS.md @@ -2,6 +2,9 @@ * The default value of `failure` argument in `parse_http_date()` is set to `structure(NA_real_, class = "Date")` so that the reponse with a "failure" date can be printed out correctly. (@shrektan, #544) +* `POST()` now uses 22 digits of precision for `body` list elements by default + (@jmwerner, #490) + # httr 1.3.1 * Re-enable on-disk caching (accidentally disabled in #457) (#475)