Hi Juerg,

I am using Apache sling as part of AEM. Adobe packages its own very similar 
class com.day.cq.commons.TidyJsonItemWriter. Of course that doesn't help if you 
aren't using AEM.

John Kramer 
Manager, AEM Engineer
E-Commerce Web Team
e: john.kra...@panerabread.com <mailto:john.kra...@panera.com>
m: 314-435-2370

On 5/12/20, 09:10, "JCR" <j...@proxymit.net> wrote:

    Thanks Daniel, John,
    
    As the app makes high usage of dynamic JCR Node features (based on 
    nt:unstructured, mixins, etc), a relatively static sling model class 
    seems a bit unpractical, though a typesafe contract would be desirable, 
    of course.
    
    On the other hand, the JsonItemWriter would almost be ideal but is not 
    present in Sling 11 anymore. Actually, the entire commons.json package 
    disappeared. Seemingly, this package has been replaced by Apache Johnzon 
    but I cannot find anything equivalent to JsonItemWriter.
    
    Anybody aware of its substitute?
    
    Thanks,
    Juerg
    
    
    On 11.05.20 16:39, John Kramer wrote:
    > You could also use a JsonItemWriter and write your own servlet if you 
want to do it that way:
    >
    > 
https://sling.apache.org/apidocs/sling8/org/apache/sling/commons/json/jcr/JsonItemWriter.html
    >
    >
    > John Kramer
    > Manager, AEM Engineer
    > E-Commerce Web Team
    > e: john.kra...@panerabread.com <mailto:john.kra...@panera.com>
    > m: 314-435-2370
    >
    > On 5/11/20, 08:54, "Daniel Klco" <dk...@apache.org> wrote:
    >
    >      Warning:  This email originated from outside of Panera. Beware of 
clicking links and attachments.
    >       
    >      
    >      Sounds like a use case for Sling Models Exporter:
    >      
    >      
https://sling.apache.org/documentation/bundles/models.html#exporter-framework-since-130-1
    >      
    >      
https://blogs.perficient.com/2018/07/26/no-servlets-required-exporting-data-with-sling-models/
    >      
    >      The only caveat is that it's designed for named parameters, if you 
really
    >      need it to be completely configurable at runtime, I'd suggest 
creating a
    >      servlet attached to a resource type that filters the current 
resources
    >      value map and uses Jackson to convert it to a JSON.
    >      
    >      On Mon, May 11, 2020 at 4:31 AM JCR <j...@proxymit.net> wrote:
    >      
    >      > Before I write anything on my own...
    >      >
    >      > Hello
    >      >
    >      > There is this convenient .json extension which produces a JSON
    >      > serialization of any given resource in Sling.
    >      >
    >      > What would be a "best practice" if I only wanted a subset of all
    >      > properties to be serialized on the json stream? That is, I would 
like to
    >      > provide a "positive" list (lists all props to be exported) or a
    >      > "negative" one (props to be excluded).
    >      >
    >      > Example: I have props a, b and c on a given node/resource and only 
a and
    >      > c should appear on the output.
    >      >
    >      > Thanks for any pattern hint
    >      > Juerg
    >      >
    >      >
    >      
    >
    
    

Reply via email to