NightJson: expand maps

This commit is contained in:
Martin Prokoph
2025-08-02 23:30:59 +02:00
parent fcf7f2a4f1
commit 504018b9f8
2 changed files with 10 additions and 4 deletions

View File

@@ -79,8 +79,9 @@ public class NightJson {
while (it.hasNext()) {
Object key = it.next();
Object val = map.get(key);
mapPairs.append("\n\t\t");
mapPairs.append(String.format("%s: %s", objToString(key, key.getClass()), objToString(val, val.getClass())));
mapPairs.append(it.hasNext() ? "," : "}");
mapPairs.append(it.hasNext() ? "," : "\n\t}");
}
return mapPairs.toString();
}
@@ -153,9 +154,9 @@ public class NightJson {
return jsonToMap(String.valueOf(submapString), k -> field.isPresent() ? getTypeArgument(field.get(), 1) : String.class);
}
else {
if (val.startsWith(" ")) val = val.substring(1);
while (val.startsWith(" ")) val = val.substring(1);
val = val.replaceAll("[\"}\n]", "");
if (val.endsWith(",")) val = val.substring(0, val.length() - 1);
while (val.endsWith(",") || val.endsWith("\n") || val.endsWith("\t")) val = val.substring(0, val.length() - 1);
return stringToObj(val, keyToType.apply(key));
}

View File

@@ -1,3 +1,8 @@
{
"scores": {"Martin": 6401}
"scores": {
"Marrrtin": 2648,
"Marrtin": 623,
"Martin": 147,
"Mark": 84
}
}