[jira] [Commented] (SLING-9455) JsonItemWriter

2020-05-22 Thread Juerg Meier (Jira)


[ 
https://issues.apache.org/jira/browse/SLING-9455?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel=17114243#comment-17114243
 ] 

Juerg Meier commented on SLING-9455:


IMHO, it does convert Resources to JSON (classes ResourceTraversor 
(https://github.com/apache/sling-org-apache-sling-servlets-get/blob/06d8e1d45c073c35b65adfcd30ed49eb6c592dfa/src/main/java/org/apache/sling/servlets/get/impl/util/ResourceTraversor.java#L34)
 
and JsonObjectBuilder.create() 
(https://github.com/apache/sling-org-apache-sling-servlets-get/blob/06d8e1d45c073c35b65adfcd30ed49eb6c592dfa/src/main/java/org/apache/sling/servlets/get/impl/util/JsonObjectCreator.java#L40).
 


A negative list would be highly desirable as I don't want sling-internal 
props like sling:resourceType, nodeType, etc. on the client side.

 >> Of course, the problem is that it's not API
Well, this is an architectural decision where I cannot contribute...





> JsonItemWriter
> --
>
> Key: SLING-9455
> URL: https://issues.apache.org/jira/browse/SLING-9455
> Project: Sling
>  Issue Type: New Feature
>  Components: Commons
>Affects Versions: Commons JSON 2.0.18
> Environment: Sling Starter
>Reporter: Juerg Meier
>Priority: Major
>
> Sling 8 came with an org.apache.sling.commons.json bundle/package. The .jcr 
> sub-package contained two classes:
>  * JsonItemWriter
>  * JsonJcrNode
> (javadoc 
> [here|https://sling.apache.org/apidocs/sling8/org/apache/sling/commons/json/jcr/package-summary.html)
> These two classes allowed for serializing a sling resource to well formated 
> JSON and a JCR node to an org.apache.sling.commons.json.JSONObject, 
> respectively.
> For legal reasons, this package was discontinued and is not present anymore 
> in later versions, including the current Sling 11 version.
> Consequently, Sling 11 lacks of a simple yet application-controllable way to 
> serialize a Resource directly to a JSON string. However, many API calls, used 
> in particular by client-side Javascript frameworks (e.g. for Single Page 
> Apps), rely heavily on JSON.
> Hence, it would be desirable to have the Sling 8 JSON package (or similar) 
> back in Sling. The following functionality should be present to have a 
> flexible JSON generator available within Sling:
>  * direct conversion of Nodes/Resources to a String containing JSON
>  * application control of node recursion levels (child nodes as JSON objects)
>  * should allow to set a negative list of properties (those not to render in 
> the output)
>  * proper rendering of all JCR property types to JSON including
>  ** date format definition (default = ISO8601)
>  ** multi-values support (as JSON arrays)
>  ** proper escaping of special chars in Strings
>  * adding additional string/value pairs by the application (i.e. not 
> originating from the dumped Resource)
> See also thread on the sling-users mailing list starting 12 May 
> 2020/"Resource to json serializing"
>  



--
This message was sent by Atlassian Jira
(v8.3.4#803005)


[jira] [Commented] (SLING-9455) JsonItemWriter

2020-05-19 Thread Robert Munteanu (Jira)


[ 
https://issues.apache.org/jira/browse/SLING-9455?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel=17111089#comment-17111089
 ] 

Robert Munteanu commented on SLING-9455:


Thanks for raising this issue [~yumeier]. I agree on the need to do this, even 
if I don't know right now what the best solution is :-)

I think that 
https://github.com/apache/sling-org-apache-sling-servlets-get/blob/06d8e1d45c073c35b65adfcd30ed49eb6c592dfa/src/main/java/org/apache/sling/servlets/get/impl/helpers/JsonRenderer.java
 covers most of your use case, except for negative list of properties, right? 
Of course, the problem is that it's not API, but I think it's a good starting 
point.

[~bdelacretaz] - IIUC the use cases are different. While you want to convert 
arbitrary objects, Juerg is looking to convert nodes or resources.

> JsonItemWriter
> --
>
> Key: SLING-9455
> URL: https://issues.apache.org/jira/browse/SLING-9455
> Project: Sling
>  Issue Type: New Feature
>  Components: Commons
>Affects Versions: Commons JSON 2.0.18
> Environment: Sling Starter
>Reporter: Juerg Meier
>Priority: Major
>
> Sling 8 came with an org.apache.sling.commons.json bundle/package. The .jcr 
> sub-package contained two classes:
>  * JsonItemWriter
>  * JsonJcrNode
> (javadoc 
> [here|https://sling.apache.org/apidocs/sling8/org/apache/sling/commons/json/jcr/package-summary.html)
> These two classes allowed for serializing a sling resource to well formated 
> JSON and a JCR node to an org.apache.sling.commons.json.JSONObject, 
> respectively.
> For legal reasons, this package was discontinued and is not present anymore 
> in later versions, including the current Sling 11 version.
> Consequently, Sling 11 lacks of a simple yet application-controllable way to 
> serialize a Resource directly to a JSON string. However, many API calls, used 
> in particular by client-side Javascript frameworks (e.g. for Single Page 
> Apps), rely heavily on JSON.
> Hence, it would be desirable to have the Sling 8 JSON package (or similar) 
> back in Sling. The following functionality should be present to have a 
> flexible JSON generator available within Sling:
>  * direct conversion of Nodes/Resources to a String containing JSON
>  * application control of node recursion levels (child nodes as JSON objects)
>  * should allow to set a negative list of properties (those not to render in 
> the output)
>  * proper rendering of all JCR property types to JSON including
>  ** date format definition (default = ISO8601)
>  ** multi-values support (as JSON arrays)
>  ** proper escaping of special chars in Strings
>  * adding additional string/value pairs by the application (i.e. not 
> originating from the dumped Resource)
> See also thread on the sling-users mailing list starting 12 May 
> 2020/"Resource to json serializing"
>  



--
This message was sent by Atlassian Jira
(v8.3.4#803005)


[jira] [Commented] (SLING-9455) JsonItemWriter

2020-05-19 Thread Bertrand Delacretaz (Jira)


[ 
https://issues.apache.org/jira/browse/SLING-9455?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel=17110935#comment-17110935
 ] 

Bertrand Delacretaz commented on SLING-9455:


FWIW, I have similar needs in the GraphQL core module, currently using 
{{json-io}} in the 
[JsonSerializer|https://github.com/apache/sling-org-apache-sling-graphql-core/blob/master/src/main/java/org/apache/sling/graphql/core/json/JsonSerializer.java]
 as that's lightweight and easy to use.

As we are using http://johnzon.apache.org/ in our 
{{org.apache.sling.commons.johnzon}} module it might make sense to use their 
{{Mapper}} for this. I haven't found much documentation about that but Steven 
Walters [provided useful information about 
it|https://lists.apache.org/thread.html/r6d7e2da06f821d816806985c8a6c1cb3820bc011d8fa2ca3a5b8b8cf%40%3Cusers.sling.apache.org%3E]
 on our users lists.

If someone writes code for this I'm happy to try it in the GraphQL core module, 
where I basically need to convert arbitrary objects (not JCR-related) to and 
from JSON.

> JsonItemWriter
> --
>
> Key: SLING-9455
> URL: https://issues.apache.org/jira/browse/SLING-9455
> Project: Sling
>  Issue Type: New Feature
>  Components: Commons
>Affects Versions: Commons JSON 2.0.18
> Environment: Sling Starter
>Reporter: Juerg Meier
>Priority: Major
>
> Sling 8 came with an org.apache.sling.commons.json bundle/package. The .jcr 
> sub-package contained two classes:
>  * JsonItemWriter
>  * JsonJcrNode
> (javadoc 
> [here|https://sling.apache.org/apidocs/sling8/org/apache/sling/commons/json/jcr/package-summary.html)
> These two classes allowed for serializing a sling resource to well formated 
> JSON and a JCR node to an org.apache.sling.commons.json.JSONObject, 
> respectively.
> For legal reasons, this package was discontinued and is not present anymore 
> in later versions, including the current Sling 11 version.
> Consequently, Sling 11 lacks of a simple yet application-controllable way to 
> serialize a Resource directly to a JSON string. However, many API calls, used 
> in particular by client-side Javascript frameworks (e.g. for Single Page 
> Apps), rely heavily on JSON.
> Hence, it would be desirable to have the Sling 8 JSON package (or similar) 
> back in Sling. The following functionality should be present to have a 
> flexible JSON generator available within Sling:
>  * direct conversion of Nodes/Resources to a String containing JSON
>  * application control of node recursion levels (child nodes as JSON objects)
>  * should allow to set a negative list of properties (those not to render in 
> the output)
>  * proper rendering of all JCR property types to JSON including
>  ** date format definition (default = ISO8601)
>  ** multi-values support (as JSON arrays)
>  ** proper escaping of special chars in Strings
>  * adding additional string/value pairs by the application (i.e. not 
> originating from the dumped Resource)
> See also thread on the sling-users mailing list starting 12 May 
> 2020/"Resource to json serializing"
>  



--
This message was sent by Atlassian Jira
(v8.3.4#803005)