You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@jackrabbit.apache.org by GitBox <gi...@apache.org> on 2022/06/01 10:20:46 UTC
[GitHub] [jackrabbit-oak] AngelaFabregues commented on a diff in pull request #582: Deeper representation of the trees with properties and in json format.
AngelaFabregues commented on code in PR #582:
URL: https://github.com/apache/jackrabbit-oak/pull/582#discussion_r886639543
##########
oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/tree/impl/AbstractTree.java:
##########
@@ -150,34 +151,60 @@ protected Iterable<String> getChildNames() {
@Override
public String toString() {
- return toString(5);
+ return toJsonString(2);
}
- private String toString(int childNameCountLimit) {
- StringBuilder sb = new StringBuilder();
- sb.append(getPath()).append(": ");
-
- sb.append('{');
- for (PropertyState p : getProperties()) {
- sb.append(' ').append(p).append(',');
- }
-
- Iterator<String> names = this.getChildNames().iterator();
- int count = 0;
- while (names.hasNext() && ++count <= childNameCountLimit) {
- sb.append(' ').append(names.next()).append(" = { ... },");
+ /**
+ * Represents an OAK tree as a JSON object string
+ * When the representation is limited in depth, {"...":"..."} represents the limit.
+ * Note that, try-catch sentences are used to add "ERROR: "+e.getMessage() values in case of representation error.
+ * Note that, this is a recursive method.
+ * @param depth tree depth to represent. Use -1 for an unlimited depth.
+ * @return json object representation of the tree as a string
+ */
+ public String toJsonString(int depth){
+ if(depth == 0){
+ return "\"...\"";
}
-
- if (names.hasNext()) {
- sb.append(" ...");
+ String str = "{";
+ str += "\"_properties_\":{ ";
+ for (PropertyState ps : this.getProperties()){
+ str+="\""+ps.getName()+"\":";
+
+ if(ps.getType().isArray()){
+ str += "[ ";
+ for(int i=0; i<ps.count(); i++){
+ try {
+ str += "\"" + jsonStringEscaper(ps.getValue(Type.STRING, i)) + "\",";
+ }catch (Exception e){
+ e.printStackTrace();
Review Comment:
True!! and it is neither needed. I will delete the e.printStackTrace();
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: dev-unsubscribe@jackrabbit.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org