@@ -53,15 +53,28 @@ private JsonObject navigateToNode(String path) {
5353 String [] parts = path .split ("\\ ." );
5454 JsonObject current = conf ;
5555
56- // Updated: Additional checks and informative logs
57- for ( String part : parts ) {
58- if (current .has (part ) && current .get (part ).isJsonObject ()) {
59- current = current .getAsJsonObject (part );
56+ // Handle a single-part path separately
57+ if ( parts . length == 1 ) {
58+ if (current .has (parts [ 0 ] ) && current .get (parts [ 0 ] ).isJsonObject ()) {
59+ return current .getAsJsonObject (parts [ 0 ] );
6060 } else {
61- //System.out.println("navigateToNode: Invalid path component: " + part );
62- return null ; // Return null when a part is invalid or not an object
61+ //System.out.println("navigateToNode: Invalid path component (single-path) : " + parts[0] );
62+ return null ;
6363 }
6464 }
65+
66+ // Iterate over path parts, ending before the last
67+ for (int i = 0 ; i < parts .length - 1 ; i ++) {
68+ JsonElement element = current .get (parts [i ]);
69+ if (element != null && element .isJsonObject ()) {
70+ current = element .getAsJsonObject ();
71+ } else {
72+ //System.out.println("navigateToNode: Invalid path component: " + parts[i]);
73+ return null ;
74+ }
75+ }
76+
77+ // Return the final parent object
6578 return current ;
6679 }
6780
@@ -132,13 +145,26 @@ public List<String> getKeys(String path) {
132145 }
133146 return keys ;
134147 }
148+
149+ //System.out.println("getKeys: No valid keys found for path = " + path + ". Make sure the path is correct.");
135150 return new ArrayList <>();
136151 }
137152
138153 public JsonElement getNode (String path ) {
139- JsonObject node = navigateToNode (path );
154+ JsonObject parentNode = navigateToNode (path );
140155 String lastPart = getLastPathPart (path );
141- return node != null && node .has (lastPart ) ? node .get (lastPart ) : null ;
156+
157+ // If the path is a single component, handle it directly
158+ if (parentNode == null && conf .has (lastPart )) {
159+ return conf .get (lastPart );
160+ }
161+
162+ if (parentNode != null && parentNode .has (lastPart )) {
163+ return parentNode .get (lastPart );
164+ }
165+
166+ //System.out.println("getNode: Could not find element for path = " + path);
167+ return null ;
142168 }
143169
144170 public void setInt (String path , int value ) {
0 commit comments