Skip to content

Commit b44da5c

Browse files
committed
Patch the infinite recursion of asJSON on subclasses of vctrs_vctr instances.
1 parent 98c6d3b commit b44da5c

File tree

4 files changed

+26
-5
lines changed

4 files changed

+26
-5
lines changed

DESCRIPTION

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,14 +21,16 @@ Description: A reasonably fast JSON parser and generator, optimized for statisti
2121
functions to stream, validate, and prettify JSON data. The unit tests included
2222
with the package verify that all edge cases are encoded and decoded consistently
2323
for use with dynamic data in systems and applications.
24+
Imports:
2425
Suggests:
2526
httr,
2627
vctrs,
2728
testthat,
2829
knitr,
2930
rmarkdown,
3031
R.rsp,
31-
sf
32-
RoxygenNote: 7.2.3
32+
sf,
33+
vctrs
34+
RoxygenNote: 7.3.1
3335
Encoding: UTF-8
3436
Roxygen: list(markdown = TRUE)

NAMESPACE

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
S3method("[",json)
44
S3method(print,json)
55
S3method(print,scalar)
6+
S3method(vec_proxy_json,vctrs_vctr)
67
export(as_gzjson_b64)
78
export(as_gzjson_raw)
89
export(base64_dec)
@@ -25,6 +26,7 @@ export(toJSON)
2526
export(unbox)
2627
export(unserializeJSON)
2728
export(validate)
29+
export(vec_proxy_json)
2830
export(write_json)
2931
import(methods)
3032
useDynLib(jsonlite,C_collapse_array)

R/asJSON.vctrs.R

Lines changed: 19 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,21 @@
11
setMethod("asJSON", "vctrs_vctr", function(x, ...) {
2-
# dispatch based on the underlying type
3-
class(x) <- setdiff(class(x), 'vctrs_vctr')
4-
asJSON(x, ...)
2+
tryCatch(
3+
{
4+
asJSON(vec_proxy_json(x), ...)
5+
},
6+
error = function(cond) {
7+
selectMethod(asJSON, "ANY")(x)
8+
}
9+
)
510
})
11+
12+
#' @export
13+
vec_proxy_json <- function(x) {
14+
UseMethod("vec_proxy_json", x)
15+
}
16+
17+
#' @export
18+
vec_proxy_json.vctrs_vctr <- function(x) {
19+
class(x) <- setdiff(class(x), "vctrs_vctr")
20+
x
21+
}

jsonlite.Rproj

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,3 +17,4 @@ StripTrailingWhitespace: Yes
1717

1818
BuildType: Package
1919
PackageInstallArgs: --no-multiarch --with-keep.source --install-tests
20+
PackageRoxygenize: rd,collate,namespace

0 commit comments

Comments
 (0)