final Node node = resource.adaptTo(Node.class);
/* Node properties to exclude from the JSON object. */
@SuppressWarnings("serial")
final Set<String> propertiesToIgnore = new HashSet<String>() {{
add("jcr:created");
add("jcr:createdBy");
add("jcr:lastModified");
add("jcr:lastModifiedBy");
add("jcr:versionHistory");
add("jcr:predecessors");
add("jcr:baseVersion");
add("jcr:uuid");
add("sling:resourceType");
add("jcr:primaryType");
}};
StringWriter stringWriter = new StringWriter();
JsonItemWriter jsonWriter = new JsonItemWriter(propertiesToIgnore);
JSONObject jsonObject = null;
try {
jsonWriter.dump(node, stringWriter, 0);
jsonObject = new JSONObject(stringWriter.toString());
return jsonObject;
} catch (RepositoryException e) {
LOG.info("Repository exception :: {} ", e);
} catch (JSONException e) {
LOG.info("JSON exception :: {} ", e);
e.printStackTrace();
} catch (Exception e) {
LOG.info("Exception :: {} ", e);
}
/* Node properties to exclude from the JSON object. */
@SuppressWarnings("serial")
final Set<String> propertiesToIgnore = new HashSet<String>() {{
add("jcr:created");
add("jcr:createdBy");
add("jcr:lastModified");
add("jcr:lastModifiedBy");
add("jcr:versionHistory");
add("jcr:predecessors");
add("jcr:baseVersion");
add("jcr:uuid");
add("sling:resourceType");
add("jcr:primaryType");
}};
StringWriter stringWriter = new StringWriter();
JsonItemWriter jsonWriter = new JsonItemWriter(propertiesToIgnore);
JSONObject jsonObject = null;
try {
jsonWriter.dump(node, stringWriter, 0);
jsonObject = new JSONObject(stringWriter.toString());
return jsonObject;
} catch (RepositoryException e) {
LOG.info("Repository exception :: {} ", e);
} catch (JSONException e) {
LOG.info("JSON exception :: {} ", e);
e.printStackTrace();
} catch (Exception e) {
LOG.info("Exception :: {} ", e);
}
Hi dosto.. General Knowledge aur aptitude ki tyaari ke liye zarur visit kare http://www.kidsfront.com/competitive-exams/general-knowledge-practice-test.html
ReplyDelete