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

Allow to configure return type in JSON array parsing #6558

Closed
sbordet opened this issue Jul 28, 2021 · 0 comments · Fixed by #6571 or #6583
Closed

Allow to configure return type in JSON array parsing #6558

sbordet opened this issue Jul 28, 2021 · 0 comments · Fixed by #6571 or #6583
Labels
Enhancement Sponsored This issue affects a user with a commercial support agreement

Comments

@sbordet
Copy link
Contributor

sbordet commented Jul 28, 2021

Target Jetty version(s)
9.4.x

Enhancement Description
Currently, JSON.parse("[1]") returns an Object[], while AsyncJSON returns List<Object>.

This is a bit inconsistent, although there is no standard, so that many different implementation return different types (e.g. Jackson vs Gson vs Jetty), so applications need to be aware of these differences and "sniff" the type before casting.

Would be great if at least within Jetty we can make this consistent, so for example provide AsyncJSON of an option such as parseArrayAsList=true|false so that it is consistent with the JSON class.

And perhaps the same to the JSON class.

For example, in CometD using the AsyncJSONTransport uses AsyncJSON and therefore arrays are parsed as lists, while WebSocketTransport uses JSON and so arrays are parsed as arrays.
Trying to deserialize that JSON into an object whose class has a setProperty(Object[] values), for example using JSONPojoConvertor, will work with one transport, but fail with the other, which is inconsistent.

@sbordet sbordet added Enhancement Sponsored This issue affects a user with a commercial support agreement labels Jul 28, 2021
sbordet added a commit that referenced this issue Aug 2, 2021
Introduced `arrayConverter` in both JSON and AsyncJSON.Factory.

Signed-off-by: Simone Bordet <simone.bordet@gmail.com>
@sbordet sbordet linked a pull request Aug 2, 2021 that will close this issue
@sbordet sbordet added this to To do in Jetty 9.4.44 FROZEN via automation Aug 2, 2021
sbordet added a commit that referenced this issue Aug 3, 2021
Fixes #6558 - Allow configuring return type in JSON array parsing.

Introduced `arrayConverter` in both JSON and AsyncJSON.Factory.

Signed-off-by: Simone Bordet <simone.bordet@gmail.com>
sbordet added a commit that referenced this issue Aug 3, 2021
Introduced `arrayConverter` in both JSON and AsyncJSON.Factory.

Signed-off-by: Simone Bordet <simone.bordet@gmail.com>
(cherry picked from commit 342396c)
@sbordet sbordet added this to To do in Jetty 10.0.7/11.0.7 FROZEN via automation Aug 3, 2021
@sbordet sbordet moved this from To do to Done in Jetty 9.4.44 FROZEN Aug 3, 2021
@sbordet sbordet moved this from To do to In progress in Jetty 10.0.7/11.0.7 FROZEN Aug 3, 2021
Jetty 10.0.7/11.0.7 FROZEN automation moved this from In progress to Done Aug 4, 2021
sbordet added a commit that referenced this issue Aug 4, 2021
Introduced `arrayConverter` in both JSON and AsyncJSON.Factory.

Signed-off-by: Simone Bordet <simone.bordet@gmail.com>
(cherry picked from commit 342396c)
sbordet added a commit that referenced this issue Sep 27, 2021
Updated JSON implementation to keep backward compatibility
by calling newArray(), now deprecated.

Signed-off-by: Simone Bordet <simone.bordet@gmail.com>
sbordet added a commit that referenced this issue Sep 27, 2021
Updated JSON implementation to keep backward compatibility
by calling newArray(), now deprecated.

Signed-off-by: Simone Bordet <simone.bordet@gmail.com>
sbordet added a commit that referenced this issue Sep 27, 2021
Updated JSON implementation to keep backward compatibility
by calling newArray(), now deprecated.

Signed-off-by: Simone Bordet <simone.bordet@gmail.com>
(cherry picked from commit 1d542be)
sbordet added a commit that referenced this issue Sep 27, 2021
Updated JSON implementation to keep backward compatibility
by calling newArray(), now deprecated.

Signed-off-by: Simone Bordet <simone.bordet@gmail.com>
(cherry picked from commit 1d542be)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Enhancement Sponsored This issue affects a user with a commercial support agreement
Projects
No open projects
1 participant