mirror of
https://github.com/overcuriousity/autopsy-flatpak.git
synced 2025-07-06 21:00:22 +00:00
Merge pull request #7805 from gdicristofaro/jsonArrAttr
fix for json array attribute value
This commit is contained in:
commit
f9ca9fdb0a
@ -348,9 +348,8 @@ public class DefaultTableArtifactContentViewer extends AbstractArtifactDetailsPa
|
|||||||
case JSON:
|
case JSON:
|
||||||
// Get the attribute's JSON value and convert to indented multiline display string
|
// Get the attribute's JSON value and convert to indented multiline display string
|
||||||
String jsonVal = attr.getValueString();
|
String jsonVal = attr.getValueString();
|
||||||
JsonObject json = JsonParser.parseString(jsonVal).getAsJsonObject();
|
JsonElement jsonEl = JsonParser.parseString(jsonVal);
|
||||||
|
value = toJsonDisplayString(jsonEl, "");
|
||||||
value = toJsonDisplayString(json, "");
|
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case STRING:
|
case STRING:
|
||||||
@ -411,19 +410,43 @@ public class DefaultTableArtifactContentViewer extends AbstractArtifactDetailsPa
|
|||||||
* @return A multi-line display string.
|
* @return A multi-line display string.
|
||||||
*/
|
*/
|
||||||
private String toJsonDisplayString(JsonElement element, String startIndent) {
|
private String toJsonDisplayString(JsonElement element, String startIndent) {
|
||||||
|
if (element == null || element.isJsonNull()) {
|
||||||
|
return "";
|
||||||
|
} else if (element.isJsonPrimitive()) {
|
||||||
|
return element.getAsString();
|
||||||
|
} else if (element.isJsonObject()) {
|
||||||
|
StringBuilder sb = new StringBuilder("");
|
||||||
|
JsonObject obj = element.getAsJsonObject();
|
||||||
|
|
||||||
StringBuilder sb = new StringBuilder("");
|
for (Map.Entry<String, JsonElement> entry : obj.entrySet()) {
|
||||||
JsonObject obj = element.getAsJsonObject();
|
appendJsonElementToString(entry.getKey(), entry.getValue(), startIndent, sb);
|
||||||
|
}
|
||||||
|
|
||||||
for (Map.Entry<String, JsonElement> entry : obj.entrySet()) {
|
String returnString = sb.toString();
|
||||||
appendJsonElementToString(entry.getKey(), entry.getValue(), startIndent, sb);
|
if (startIndent.length() == 0 && returnString.startsWith(NEW_LINE)) {
|
||||||
|
returnString = returnString.substring(NEW_LINE.length());
|
||||||
|
}
|
||||||
|
return returnString;
|
||||||
|
} else if (element.isJsonArray()) {
|
||||||
|
StringBuilder sb = new StringBuilder("");
|
||||||
|
JsonArray jsonArray = element.getAsJsonArray();
|
||||||
|
if (jsonArray.size() > 0) {
|
||||||
|
int count = 1;
|
||||||
|
for (JsonElement arrayMember : jsonArray) {
|
||||||
|
sb.append(NEW_LINE).append(String.format("%s%d", startIndent, count));
|
||||||
|
sb.append(toJsonDisplayString(arrayMember, startIndent.concat(INDENT_RIGHT)));
|
||||||
|
count++;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
String returnString = sb.toString();
|
||||||
|
if (startIndent.length() == 0 && returnString.startsWith(NEW_LINE)) {
|
||||||
|
returnString = returnString.substring(NEW_LINE.length());
|
||||||
|
}
|
||||||
|
return returnString;
|
||||||
|
} else {
|
||||||
|
return "";
|
||||||
}
|
}
|
||||||
|
|
||||||
String returnString = sb.toString();
|
|
||||||
if (startIndent.length() == 0 && returnString.startsWith(NEW_LINE)) {
|
|
||||||
returnString = returnString.substring(NEW_LINE.length());
|
|
||||||
}
|
|
||||||
return returnString;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
Loading…
x
Reference in New Issue
Block a user