Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

response-transformer doesn't handle empty JSON array well #1208

Closed
ukcuf opened this issue May 13, 2016 · 4 comments
Closed

response-transformer doesn't handle empty JSON array well #1208

ukcuf opened this issue May 13, 2016 · 4 comments
Assignees
Labels

Comments

@ukcuf
Copy link

ukcuf commented May 13, 2016

response-tranformer by default would do response body's transformation by cjson.decode(), and later does a cjson.encode() even if no transformation to response body is required.

This uses cjson.decode() and cjson.encode() but cjson's current version from luarocks does not handle empty array well in below case:

local json_str = '{"items":[],"properties":{}}'
local json_str_foo = cjson.encode(cjson.decode(json_str))

The json_str_foo becomes:
{"items":{},"properties":{}}

instead of '{"items":[],"properties":{}}' as expected.

This is caused by this issue from cjson: mpx/lua-cjson#11

If using response-transformer is an only choice to transform response body, this defect looks like to block some use scenarios that our services return empty array in JSON as part of the response body.

@Tieske
Copy link
Member

Tieske commented Jul 19, 2016

even if no transformation to response body is required

#1263 fixes a bug that included decoding an encoding the body even when no body modifications were configured. So that part is fixed in de upcoming 0.9 release.

@Tieske Tieske modified the milestones: 0.9, 0.10 Jul 22, 2016
@subnetmarco
Copy link
Member

@Tieske can we close this?

@thibaultcha
Copy link
Member

See openresty/lua-cjson#6 for a potential fix to this

@thibaultcha thibaultcha removed this from the 0.10 RC milestone Mar 7, 2017
kikito added a commit that referenced this issue Aug 13, 2019
When a response contains an empty array and it gets transformed, the empty array should remain an empty array (and not get transformed into an empty cjson object).

Fixes #1208.
hishamhm pushed a commit that referenced this issue Aug 13, 2019
When a response contains an empty array and it gets transformed, the empty array should remain an empty array (and not get transformed into an empty cjson object).

Fixes #1208.
@bungle
Copy link
Member

bungle commented Aug 15, 2019

I will close this as a fix to it was merged.

@bungle bungle closed this as completed Aug 15, 2019
hishamhm pushed a commit that referenced this issue Aug 15, 2019
When a response contains an empty array and it gets transformed, the empty array should remain an empty array (and not get transformed into an empty cjson object).

Fixes #1208.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

7 participants