Skip to content
Snippets Groups Projects
Commit c6b68ab9 authored by Mirco Nasuti's avatar Mirco Nasuti
Browse files

fix double quoted-prettified json in experiments API

parent ae18943a
No related branches found
No related tags found
No related merge requests found
......@@ -101,7 +101,7 @@ public class ExperimentApi {
}
} catch (MalformedURLException mue) { LOGGER.trace(mue.getMessage()); } // ignore
return new ResponseEntity<>(gson.toJson(experiment), HttpStatus.OK);
return new ResponseEntity<>(gson.toJson(experiment.jsonify()), HttpStatus.OK);
}
@ApiOperation(value = "get an experiment", response = Experiment.class)
......@@ -126,7 +126,7 @@ public class ExperimentApi {
return new ResponseEntity<>("Not found", HttpStatus.NOT_FOUND);
}
return new ResponseEntity<>(gson.toJson(experiment), HttpStatus.OK);
return new ResponseEntity<>(gson.toJson(experiment.jsonify()), HttpStatus.OK);
}
@ApiOperation(value = "Mark an experiment as viewed", response = Experiment.class)
......@@ -154,7 +154,7 @@ public class ExperimentApi {
LOGGER.info("Experiment updated (marked as viewed)");
return new ResponseEntity<>(gson.toJson(experiment), HttpStatus.OK);
return new ResponseEntity<>(gson.toJson(experiment.jsonify()), HttpStatus.OK);
}
@ApiOperation(value = "Mark an experiment as shared", response = Experiment.class)
......@@ -282,7 +282,7 @@ public class ExperimentApi {
LOGGER.info("Experiment updated (marked as shared)");
return new ResponseEntity<>(gson.toJson(experiment), HttpStatus.OK);
return new ResponseEntity<>(gson.toJson(experiment.jsonify()), HttpStatus.OK);
}
private void sendExperiment(Experiment experiment) throws MalformedURLException {
......
package eu.hbp.mip.model;
import com.google.gson.Gson;
import com.google.gson.GsonBuilder;
import com.google.gson.JsonArray;
import com.google.gson.JsonObject;
import com.google.gson.*;
import com.google.gson.annotations.Expose;
import org.apache.log4j.Logger;
import org.hibernate.annotations.Cascade;
import javax.persistence.*;
import java.util.*;
import java.util.Date;
import java.util.LinkedList;
import java.util.List;
import java.util.UUID;
/**
* Created by habfast on 21/04/16.
......@@ -137,6 +137,34 @@ public class Experiment {
return new Gson().toJson(queryElements);
}
public JsonObject jsonify() {
JsonObject exp = new Gson().toJsonTree(this).getAsJsonObject();
JsonParser parser = new JsonParser();
if (this.algorithms != null)
{
exp.remove("algorithms");
JsonArray jsonAlgorithms = parser.parse(this.algorithms).getAsJsonArray();
exp.add("algorithms", jsonAlgorithms);
}
if (this.validations != null)
{
exp.remove("validations");
JsonArray jsonValidations = parser.parse(this.validations).getAsJsonArray();
exp.add("validations", jsonValidations);
}
if (this.result != null)
{
exp.remove("result");
JsonArray jsonResult = parser.parse(this.result).getAsJsonArray();
exp.add("result", jsonResult);
}
return exp;
}
public String getValidations() {
return validations;
}
......
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment