Hi All ,
Wanted to know if there are any utility classes which can be used to create jcr nodes from json string ? I actually would execute a rest service which would return a proper json response with key value pairs . I would have normally parsed the whole json add properties required for jcr like 'node type as unstructured property ' and execute curl by passing in a sling servlet url which would return this json response .
However i was wondering if I can use any utility classes which can off load parsing and adding necessary properties required for jcr ?
Thanks in advance
Solved! Go to Solution.
Views
Replies
Total Likes
below is the steps I followed
Bundle A
1. Convert JSON to Object o1 using jackson (annotation based)
2. pass o1 to bundle B
Bundle B
1. Map the object o1 to Object o2 which is annotated for Jcrom (This was needed as there was some business logic needed before storing it in nodes)
2. convert o2 to jcr nodes using JCROM (annotation based)
In this way Bundle B can accept object from any bundles. Convert/Map them to the object value which needs to be stored.
Hope it helps/solves your need...
Views
Replies
Total Likes
Write a custom OSGi service that parses JSON and then use the JCR API to create nodes.
Views
Replies
Total Likes
I had a similar requirement and implemented as below
This can be done in 2 steps using utilities.
Step 1: convert JSON to Java object using 'GSON' or 'Jackson'
Step 2: convert java object to jcr node using 'Jcrom'
'This helped me in modulerizing as JSON was the response from one bundle and its consumed by another bundle.
~Loki
Views
Replies
Total Likes
This seems to be very good approach as we would be dealing with objects . JCrom normally relies on annotations on java objects to convert to jcr nodes . So when you get your objects from GSON what were you using to get them annotated ?
Views
Replies
Total Likes
below is the steps I followed
Bundle A
1. Convert JSON to Object o1 using jackson (annotation based)
2. pass o1 to bundle B
Bundle B
1. Map the object o1 to Object o2 which is annotated for Jcrom (This was needed as there was some business logic needed before storing it in nodes)
2. convert o2 to jcr nodes using JCROM (annotation based)
In this way Bundle B can accept object from any bundles. Convert/Map them to the object value which needs to be stored.
Hope it helps/solves your need...
Views
Replies
Total Likes
Thanks for sharing . Nice approach and always dealing with objects is the best part.
Views
Replies
Total Likes