xpol/lua-rapidjson

Encoding to array instead of object for 'mixed' tables

stepelu opened this issue · 10 comments

Example:

rapidjson.encode({a = 2, 1, 2}) --> [1.0,2.0]

According to the documentation it should be threated as an object, as the table does not contain only integer keys from 1 to n.

xpol commented

It contains integers 1 to 2.
I'll check it later.

Thanks for the prompt reply.

Yes, but the documentation says it's threted as an object if either the array option is set via __jsontype or if 'table contains only integer keys from 1 to n' (notice the word 'only').

So either the code or the documentation should be changed.
I am fine with either, I do not know what you're trying to achieve.

xpol commented

I'm trying to do changes like:

  • A table is encoded as json array if:
    • have meta field __jsontype set to 'array'.
    • don't have meta filed __jsontype and length > 0.
  • When table is encoded as json object, only string keys and its values are encoded.

That's fine to me.

xpol commented

@stepelu
I have just released 0.4.0, you can install via luarocks install rapidjson.
And updated doc.

Thanks for the update.

As soon as the upgrade to the new luarocks is finished I will add it to my
distribution as well.

BTW, are you using the latest rapidjson?
They fixed an issue I opened for the serialization of Nan.
On 25 Jan 2016 05:32, "xpol" notifications@github.com wrote:

@stepelu https://github.com/stepelu
I have just released 0.4.0, you can install via luarocks install rapidjson
.
And updated doc
https://github.com/xpol/lua-rapidjson#value-type-mappings.


Reply to this email directly or view it on GitHub
#9 (comment).

xpol commented

@stepelu
It seems not included that fix.
I'll do a subtree pull and release again.

xpol commented

You may try 0.4.2 now.

NaN encoding, i.e. encode(0/0), is not throwing an error (nil + error message).
I expected so according to: Tencent/rapidjson#509

xpol commented

Close this for now.
Feel free to reopen if the 'mixed' table issue has not fixed.