jeroen / jsonlite

A Robust, High Performance JSON Parser and Generator for R
http://arxiv.org/abs/1403.2805
Other
376 stars 40 forks source link

[jsonliet>>R]: Using jsonlite with R for serializing classes inherited from list #362

Open vabeykoon opened 3 years ago

vabeykoon commented 3 years ago

I am trying to serialize the following class and unserialize it usage the jsonlite binding for R.

setClass("Complexo",
         contains = c("list"),
         validity = function(object) {
           !is.null(object$name)
         }
)

complex1 <- new("Complexo")
c1 = jsonlite::serializeJSON(complex1)
jsonlite::unserializeJSON(c1)

When I try this, I am getting the following error,

Error in structure(.Data = base::quote(list()), .Data = base::quote(NULL)) : 
  formal argument ".Data" matched by multiple actual arguments

Any suggestions why I am getting this issue?

george-chamoun commented 3 years ago

I'm thinking this could also occur when any S4 extends another SEXPTYPE and therefore class(S4 extending SEXPTYPE) != typeof(S4 extending SEXPTYPE).

jeroen commented 3 years ago

Yes that looks like a bug. I don't use S4 myself, do you have a suggestion for a solution?

george-chamoun commented 3 years ago

Hi, I opened a with PR that addresses most of the SEXP types with minimal changes to code. I also added some tests.