Skip to content

Commit

Permalink
Add handling for lists in results
Browse files Browse the repository at this point in the history
  • Loading branch information
vogti committed Dec 10, 2023
1 parent c08d974 commit 42b3902
Showing 1 changed file with 8 additions and 1 deletion.
9 changes: 8 additions & 1 deletion src/main/java/ch/unibas/dmi/dbis/chronos/agent/Utils.java
Original file line number Diff line number Diff line change
Expand Up @@ -29,16 +29,23 @@ of this software and associated documentation files (the "Software"), to deal
import java.io.PrintWriter;
import java.io.UnsupportedEncodingException;
import java.nio.charset.StandardCharsets;
import java.util.List;
import java.util.Map;
import java.util.Properties;
import kong.unirest.json.JSONArray;
import kong.unirest.json.JSONObject;

class Utils {

static void saveResults( final Properties executionResults, final File resultsJsonFile ) throws IllegalStateException {
JSONObject resultsJsonObject = new JSONObject();
for ( Map.Entry<Object, Object> result : executionResults.entrySet() ) {
resultsJsonObject.put( result.getKey().toString(), result.getValue().toString() );
Object obj = result.getValue();
if ( obj instanceof List<?> ) {
resultsJsonObject.put( result.getKey().toString(), new JSONArray( (List<?>) obj ) );
} else {
resultsJsonObject.put( result.getKey().toString(), obj.toString() );
}
}

try ( PrintWriter out = new PrintWriter( resultsJsonFile, StandardCharsets.UTF_8.name() ) ) {
Expand Down

0 comments on commit 42b3902

Please sign in to comment.