You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@sling.apache.org by José Correia <me...@gmail.com> on 2022/06/02 08:07:08 UTC

Improve JSON serialization and response data types

Hello!

While working on the Distribution API I noticed some code smells that I
would like to discuss and see if we have a solution already implemented in
any Sling repository:


   - *Java/JSON serialization*

Currently, we are implementing our own serializer in the form of a generic
utils class: ServletJsonUtils.java
<https://github.com/apache/sling-org-apache-sling-distribution-core/blob/master/src/main/java/org/apache/sling/distribution/servlet/ServletJsonUtils.java>.
This means more code to maintain and higher complexity if we want to change
the format of the JSON responses.

*Are we already using any JSON serialization library out there?* Was this
done on purpose to reduce dependencies?


   - *JSON response data types*

Every JSON response in the API is built on-demand in the servlet layer
<https://github.com/apache/sling-org-apache-sling-distribution-core/blob/master/src/main/java/org/apache/sling/distribution/servlet/DistributionPackageImporterServlet.java#L119>.
This is contributing to increased complexity in these endpoints and makes
it hard to efficiently grasp how the API works.
This is an opinionated topic, but I tend to enjoy APIs that have
well-defined request/response objects since the behavior becomes very easy
to understand, and it increases readability in the transport layer.

*What do you think?* Are we implementing a similar pattern elsewhere?


Cheers,

José Correia

Re: Improve JSON serialization and response data types

Posted by Konrad Windszus <kw...@apache.org>.
In places where the size/number of dependencies really matters we also embedded (via Bnds conditionalpackage, https://bnd.bndtools.org/instructions/conditionalpackage.html) the minimum implementation provided by Felix Utils: https://github.com/apache/felix-dev/tree/master/utils/src/main/java/org/apache/felix/utils/json

Both parser and serialiser are very lean and are don’t have any external dependencies.

For all other cases javax.json is the way to go.
Konrad
 
> On 3. Jun 2022, at 11:50, Bertrand Delacretaz <bd...@apache.org> wrote:
> 
> Le ven. 3 juin 2022 à 11:46, Julian Reschke <ju...@gmx.de> a écrit :
>> ...I believe the answer is javax.json.
> 
> Yes, many "newer" Sling modules are using that.
> 
> I think the homegrown JSON code is here for historical reasons.
> 
> If someone wants to change that that's fine, but backwards
> compatibility has to be preserved.
> 
> The strong modularity of Sling means it's not necessarily a problem
> (even if not optimal) to use different techniques in different
> modules. To be evaluated on a case-by-case basis, IMO.
> 
> -Bertrand


Re: Improve JSON serialization and response data types

Posted by Bertrand Delacretaz <bd...@apache.org>.
Le ven. 3 juin 2022 à 11:46, Julian Reschke <ju...@gmx.de> a écrit :
> ...I believe the answer is javax.json.

Yes, many "newer" Sling modules are using that.

I think the homegrown JSON code is here for historical reasons.

If someone wants to change that that's fine, but backwards
compatibility has to be preserved.

The strong modularity of Sling means it's not necessarily a problem
(even if not optimal) to use different techniques in different
modules. To be evaluated on a case-by-case basis, IMO.

-Bertrand

Re: Improve JSON serialization and response data types

Posted by Julian Reschke <ju...@gmx.de>.
Am 03.06.2022 um 11:42 schrieb Christian Schneider:
> I suspect we use a home grown serialisation to minimise dependencies but I
> don't know.
> So I would be interested in what others say.
> What is our strategy/recommendation in sling when producing json?
>
> Christian

I believe the answer is javax.json.

Best regards, Julian

Re: Improve JSON serialization and response data types

Posted by Christian Schneider <ch...@die-schneider.net>.
I suspect we use a home grown serialisation to minimise dependencies but I
don't know.
So I would be interested in what others say.
What is our strategy/recommendation in sling when producing json?

Christian

Am Do., 2. Juni 2022 um 10:07 Uhr schrieb José Correia <
menesesjmmc@gmail.com>:

> Hello!
>
> While working on the Distribution API I noticed some code smells that I
> would like to discuss and see if we have a solution already implemented in
> any Sling repository:
>
>
>    - *Java/JSON serialization*
>
> Currently, we are implementing our own serializer in the form of a generic
> utils class: ServletJsonUtils.java
> <
> https://github.com/apache/sling-org-apache-sling-distribution-core/blob/master/src/main/java/org/apache/sling/distribution/servlet/ServletJsonUtils.java
> >.
> This means more code to maintain and higher complexity if we want to change
> the format of the JSON responses.
>
> *Are we already using any JSON serialization library out there?* Was this
> done on purpose to reduce dependencies?
>
>
>    - *JSON response data types*
>
> Every JSON response in the API is built on-demand in the servlet layer
> <
> https://github.com/apache/sling-org-apache-sling-distribution-core/blob/master/src/main/java/org/apache/sling/distribution/servlet/DistributionPackageImporterServlet.java#L119
> >.
> This is contributing to increased complexity in these endpoints and makes
> it hard to efficiently grasp how the API works.
> This is an opinionated topic, but I tend to enjoy APIs that have
> well-defined request/response objects since the behavior becomes very easy
> to understand, and it increases readability in the transport layer.
>
> *What do you think?* Are we implementing a similar pattern elsewhere?
>
>
> Cheers,
>
> José Correia
>


-- 
-- 
Christian Schneider
http://www.liquid-reality.de

Computer Scientist
http://www.adobe.com